From org.json JSONObject to org.codehaus.jackson

后端 未结 3 2062
故里飘歌
故里飘歌 2021-02-05 23:10

I want to move from org.json to org.codehaus.jackson. How do I convert the following Java code?

private JSONObject myJsonMessage(String         


        
3条回答
  •  遥遥无期
    2021-02-05 23:34

    Instead of JSONObject use Jackson's ObjectMapper and ObjectNode:

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    node.put("message", "text");
    

    This would be Jackson's equivalent of your current org.json code.

    However, where Jackson really excels is in its capacity to do complex mappings between your Java classes (POJOs) and their JSON representation, as well as its streaming API which allows you to do really fast serialization, at least when compared with org.json's counterparts.

提交回复
热议问题