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.
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 the com.fasterxml.jackson.databind.node
package.
ObjectNode
ObjectNode
is a concrete implementation of JsonNode
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With