Spring和Jackson中的JSONObject替代品 [英] JSONObject Alternative in Spring and Jackson
问题描述
我需要将地图传递回Web应用程序。
I need to pass a map back to the web application.
我习惯将地图封装在JSONObject中
I'm used to encapsulating the map in a JSONObject
但是因为我使用Spring和Jackson Haus。
But since I am using Spring and Jackson Haus.
是否有更简单的方法来维护pojo?我可以只注释MAP吗?
is there an easier way to maintain the pojo? May I can just annotate the MAP ?
推荐答案
杰克逊有 com.fasterxml.jackson.core.JsonNode
,以及 ObjectNode
等特定子类型。
这些形式是所谓的树模型
,这是与Jackson一起处理JSON的三种方法之一 - 其他一些库(如 org) .json
)只提供这种方式。
Jackson has com.fasterxml.jackson.core.JsonNode
, and specific subtypes like ObjectNode
.
These form so-called Tree Model
, which is one of 3 ways to handle JSON with Jackson -- some other libraries (like org.json
) only offer this way.
所以你应该可以只使用 JsonNode
相反;使用 org.json
库没有什么意义;它很慢,并且已经过时了。
So you should be able to just use JsonNode
instead; there is little point in using org.json
library; it is slow, and has outdated API.
或者你只需使用 java.util.Map
,然后返回那。杰克逊可以处理标准的列表
,地图
和其他JDK类型。
Alternatively you can just use java.util.Map
, and return that. Jackson can handle standard List
s, Map
s and other JDK types just fine.
这篇关于Spring和Jackson中的JSONObject替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!