Convert Java Object to Json and Vice versa? -
i know json object nothing string
.
my question have map of object , want convert json format.
example :
java class -> class person{ private string name; private string password; private int number; } java list -> map<list<long>,list<person>> map=new hashmap<list<long>,list<person>>(); ..and map has data filled in it.
i want convert list
json format?
how can achieve it? because want send on httpclient... if not other alternative way?
as per knowledge there gson api
available, dont know how use , or in other efficient way.
thank you
not sure problem gson is. the doc:
bagofprimitives obj = new bagofprimitives(); gson gson = new gson(); string json = gson.tojson(obj);
and
bagofprimitives obj2 = gson.fromjson(json, bagofprimitives.class);
that object (as name suggests) made of primitives. gson trivially handle objects, collections of objects etc. life gets little more complex when using generics etc., example above expect gson work little trouble.
Comments
Post a Comment