Library to encode/decode from json to java.util.Map?

后端 未结 6 1712
野趣味
野趣味 2020-12-05 05:44

Does anyone knows a java library that could easily encode java Maps into json objects and the other way around?

UPDATE

For reasons couldn\'

6条回答
  •  难免孤独
    2020-12-05 06:00

    I guess the real question would be which JSON library (from org.json's page) would NOT allow doing this. As far as I know every single library there would allow this in some form. So every library mentioned so far works.

    And to add some information, Jackson works very well with all kinds of data including basic Maps and Lists:

    ObjectMapper mapper = new ObjectMapper();
    String json = mapper.writeValue(list);
    List listOfMaps = mapper.readValue(json, List.class);
    

    which would handle this particular case. While generic type information can be used, it is optional when using "natural" binding to JDK container types.

提交回复
热议问题