From org.json JSONObject to org.codehaus.jackson

后端 未结 3 2058
故里飘歌
故里飘歌 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:17

    If you want to upgrade from org.json library to Jackson piece by piece, and initially retaining same API, you might want to read "Upgrade from org.json to Jackson". This would at least make your code about 3x faster for basic JSON reading and writing; plus you could -- if you so choose -- start converting processing, as Jackson makes it easy to convert between Trees and POJOs (ObjectMapper.treeToValue(...), valueToTree, convertValue between POJOs etc. etc).

    Just keep in mind that tools that you are familiar with may bias your thinking to certain patterns, and keeping an open mind can help you find even better ones. In case of Jackson (or GSON or other mature Java JSON tools), you really should consider where proper data-binding could help, instead of using JSON-centered tree model (that org.json offers). Tree Models keep your thinking grounded to JSON structure, which is sometimes useful; but might also prevent you from seeing more natural patterns that come from defining POJO structure to reflect expected JSON, and operating on Java Objects directly.

提交回复
热议问题