I am trying to dynamically parse JSON on a map. The following works well with plain JSON
String easyString = "{\"name\":\"mkyong\", \"age\":\"29\"}"; Map<String,String> map = new HashMap<String,String>(); ObjectMapper mapper = new ObjectMapper(); map = mapper.readValue(easyString, new TypeReference<HashMap<String,String>>(){}); System.out.println(map);
But it fails when I try to use more complex JSON with embedded information. I am trying to analyze sample data from json.org
{ "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": { "GlossEntry": { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": { "para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": [ "GML", "XML" ] }, "GlossSee": "markup" } } } } }
I get the following error
An exception in the stream "main" com.fasterxml.jackson.databind.JsonMappingException: it is not possible to deserialize an instance of java.lang.String from the START_OBJECT token
Is there a way to parse complex JSON data into a map?
source share