fyhack / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Cannot deserialize JSON into a JsonObject #201

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a Gson() object
2. Attempt to deserialize a Json string into a JsonObject instance
3. Watch as you get an empty JsonObject

What is the expected output? What do you see instead?
It would be nice to have the JsonObject be populated with the fields and
values from the Json string. This doesn't happen, and instead we receive an
empty Json object. This is likey to be caused because there is a lack of a
custom deserializer for JsonObject, which would fill it up with the fields
in the Json string.

What version of the product are you using? On what operating system?
Version 1.4, on OpenSuse Linux

Original issue reported on code.google.com by paul.gib...@gmail.com on 14 Apr 2010 at 7:33

GoogleCodeExporter commented 9 years ago
There is a workaround. What you can do is write your own custom JsonObject
deserializer, and its very simple. I've attached the source.

Its as simple as having a deserializer that returns a JsonObject with this as 
the
method body for the method "deserialize":

return json.getAsJsonObject();

Original comment by paul.gib...@gmail.com on 14 Apr 2010 at 8:11

Attachments:

GoogleCodeExporter commented 9 years ago
The workaround should be sufficient.

Original comment by limpbizkit on 3 Sep 2010 at 6:46