Jackson JSON与JsonNode和ObjectNode之间的区别 [英] Jackson JSON difference between JsonNode and ObjectNode
问题描述
我正在使用Jackson进行JSON解析。
JsonNode和ObjectNode之间有什么区别。
用于以字符串格式映射json。
快速回答
-
I am using Jackson for JSON parsing. What is the difference between JsonNode and ObjectNode.
And which to use for mapping json in string format.
解决方案Quick answer
JsonNode
: Abstract class, used when reading a JSON document.ObjectNode
: Concrete implementation, used when building or modifying a JSON document.
Keep reading for a more detailed answer.
JsonNode
JsonNode
is an abstract class used as the base class for all JSON nodes, which form the basis of JSON Tree Model that Jackson implements.Quoting the
JsonNode
documentation:As a general design rule, most accessors (getters) methods are included in this base class, to allow for traversing structure without type casts.
Mutators methods (setters), however, need to be accessed through specific sub-classes (such as
ObjectNode
andArrayNode
).This seems sensible because proper type information is generally available when building or modifying trees, but less often when reading a tree (newly built from parsed JSON content).
The
JsonNode
concrete implementations can be found in thecom.fasterxml.jackson.databind.node
package.ObjectNode
ObjectNode
is a concrete implementation ofJsonNode
that maps a JSON object and a JSON object is defined as following:An object is an unordered set of name/value pairs. An object begins with
{
(left brace) and ends with}
(right brace). Each name is followed by:
(colon) and the name/value pairs are separated by,
(comma).这篇关于Jackson JSON与JsonNode和ObjectNode之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!