java - JSON - deserialization of dynamic object using Gson -
java - JSON - deserialization of dynamic object using Gson -
let's imagine have java class of type:
public class myclass { public string par1; public object par2; }
then have this:
string json = "{"par1":"val1","par2":{"subpar1":"subval1"}}"; gson gson = new gsonbuilder.create(); myclass mclass = gson.fromjson(json, myclass.class);
the par2
json given me other application , don't ever know it's parameter names, since dynamic.
my question is, class type should par2
variable on myclass set to, json string variable correctly deserialized class object?
thanks
check out serializing , deserializing generic types gson user guide:
public class myclass<t> { public string par1; public t par2; }
to deserialize it:
type footype = new typetoken<myclass<foo>>() {}.gettype(); gson.fromjson(json, footype);
hope help.
java json gson
Comments
Post a Comment