I am using Jackson for JSON parsing.
What is the difference between JsonNode
and ObjectNode
?
And which to use for mapping JSON in string fo
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 and ArrayNode).
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).