spring - RestTemplate getForObject to POJO -


i'm using resttemplate.getforobject() retrieve json includes couple of objects , arrays, want convert 1 of objects inside json pojo, don't care other objects inside json.

what proper way approach this?


edit:

another approach accepted answer, can use jacksons objectmapper

@autowired private objectmapper jacksonobjectmapper; 

then

linkedhashmap obj1 = resttemplate.getforobject(uri, linkedhashmap.class, params); linkedhashmap obj2 = (linkedhashmap)test.get("flightstatuses");  flight flight = jacksonobjectmapper.convertvalue(obj2, flight.class); 

you idea, generic datatype json structure use objectmapper convert class need.

one solution create wrapper class, includes pojo want deserialize , ignore other properties using @jsonignoreproperties. retrieve wrapper object , pojo it.

@jsonignoreproperties(ignoreunknown=true) public class wrapper {      private mypojo mypojo; }  mypojo mypojo = resttemplate.getforobject("url", wrapper.class).getmypojo(); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -