json - Gson from Object To Object -
json - Gson from Object To Object -
i'm trying json converter of map generic object. assuming have next example:
class myclass1 { string v1; boolean v2; } class myclass2 { integer v3; string v4; } class mycontainer { map<string, object>lst; mycontainer() { lst = new hashmap<string, object>(); } } public main() { mycontainer c1, c2; gson g = new gson(); c1 = new mycontainer(); myclass1 my1 = new myclass1(); myclass2 my2 = new myclass2(); my1.v1 = "v1"; my1.v2 = true; my2.v3 = 10; my2.v4="v4"; c1.lst.put("myclass1", my1); c1.lst.put("myclass2", my2); string json = g.tojson(c1); c2 = g.fromjson(json, mycontainer.class);
when utilize g.tojson have json result but, when phone call g.fromjson doesn't convert because cannot understand class must utilize in order map input json. infact, c2.lst.get("myclass1") not homecoming instance of myclass1 com.google.gson.internal.stringmap
json object gson
Comments
Post a Comment