Convert JSON data to a list of Java objects -


i have json data that:

[ {     "data": "data",     "what": "what2",     "when": 1392046352,     "id": 13,     "tags": "checkid:testcheckid, target:server.id.test, id:testid" }, {     "data": "test",     "what": "test",     "when": 1395350977,     "id": 5,     "tags": "checkid:testcheckid, target:server.id.test, id:testid" } ] 

i have java class , want convert json list of instances of class. found how convert single object, not list.

with jackson like:

string jsonstr = "..."; objectreader reader = new objectmapper().reader(); list<map<string, object>> objs = reader.readvalue(jsonstr);  map<string, object> myfirstobj = objs.get(0); myfirstobj.get("data"); myfirstobj.get("what"); // , on 

or better can create pojo , do:

string jsonstr = "..."; objectmapper mapper = new objectmapper(); list<mypojo> myobjs = mapper.readvalue(jsonstr, new typereference<list<mypojo>>() {}); mypojo mypojo = myobjs.get(0); mypojo.getdata(); mypojo.getwhat(); // , on 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -