I am using gson to deserialize POJOs from JSON views.
I would like one of the fields in one of my POJOs to contain arbitrary JSON data. For instance:
class B { public String stringField; public JsonObject jsonField; }
I would like to call Gson.fromJson(json, B.class) on the following JSON:
{ "stringField": "booger", "jsonField" : { "arbitraryField1": "foo" } }
and get a B.jsonField containing a JsonObject with arbitraryField foo values.
However, when I try to do this, jsonField always an empty object ( {} ). In fact, more generally, it seems that the following always returns an empty object:
new Gson().fromJson("{ foo: 1 }", JsonObject.class)
I would expect the above to return an object containing a field named foo value 1.
How can I save gson arbitrary json data while json deserialization for POJOS?
emmby source share