How to Convert JSON string to Map using Jackson

  Apr 2, 2019

I have basic idea of how Jackson converts to and from an json to Java object, i was wondering how to do a map conversion directly from json to java.

Solved 0
4 months ago 1 Answer 0 views

Answers ( 1 )

  1. 4 months ago

    Here is a good example:

    try {
                ObjectMapper mapper = new ObjectMapper();
                String json = "{\"name\":\"tbc\", \"age\":20}";
                Map<String, Object> map = new HashMap<String, Object>();
                // convert JSON string to Map
                map = mapper.readValue(json, new TypeReference<Map<String, String>>(){});
            } catch (JsonGenerationException e) {
            } catch (JsonMappingException e) {
            } catch (IOException e) {

*Avoid using any other website url of links , otherwise your answer may not be visible on website until verification is complete.

Your Answer