Jackson JSON User Group

JSON in Java the Right Way -- Action, Jackson!

hello

 I hava a json string for the following format

{"Facets":[{"category":"Person","count":17,"Person":[{"count":1,"entity":"Al Faw"},{"count":1,"entity":"Col. Barry Johnson"},{"count":1,"entity}]}

i want to convert back it to a hash map.Is there any way to convert json back to java object

Thanks in advance

Views: 2941

Comment by Tatu Saloranta on December 6, 2011 at 10:29pm

Yes, you can bind JSON to a POJO or HashMap, both using ObjectMapper.readValue() method, like:

   ObjectMapper mapper = new ObjectMapper();

   Map<String,Object> map = mapper.readValue(jsonInput, Map.class);

   MyBean bean = mapper.readValue(jsonInput, MyBean.class); // assuming it has proper public fields or setters

Comment

You need to be a member of Jackson JSON User Group to add comments!

Join Jackson JSON User Group

© 2013   Created by Tatu Saloranta.   Powered by

Badges  |  Report an Issue  |  Terms of Service