Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ObjectNode and JsonNode in Jackson?

According to the documetation of JsonNode:

Most mutators, however, need to be accessed through specific sub-classes (such as ObjectNode and ArrayNode).

However I am still confused since some stackoverflow answers seem to use them quite interchangeably. What different purpose do they serve?

like image 772
THIS USER NEEDS HELP Avatar asked Aug 01 '16 18:08

THIS USER NEEDS HELP


People also ask

What is Jackson ObjectNode?

Method that can be used for efficient type detection when using stream abstraction for traversing nodes. ObjectNode. deepCopy() Method that can be called to get a node that is guaranteed not to allow changing of this node through mutators on this node or any of its children.

What is JsonNode Jackson?

JsonNode is Jackson's tree model (object graph model) for JSON. Jackson can read JSON into a JsonNode instance, and write a JsonNode out to JSON. This Jackson JsonNode tutorial will explain how to deserialize JSON into a JsonNode and serialize a JsonNode to JSON.

What is the difference between JsonNode and Jsonobject?

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.

How do I modify JsonNode Jackson?

How to modify JsonNode with Java Jackson? The JsonNode class is immutable. That means we cannot modify it. For that purpose, we can use the ObjectNode, which is the subclass of the JsonNode.


1 Answers

JsonNode is a base class that ObjectNode and ArrayNode extend. JsonNode represents any valid Json structure whereas ObjectNode and ArrayNode are particular implementations for objects (aka maps) and arrays, respectively.

ArrayNode has specific methods for dealing with arrays such as get(index i) E.g. you cannot get an item at a specific index in a JsonNode or ObjectNode but you can in an ArrayNode.

like image 70
bhspencer Avatar answered Sep 26 '22 16:09

bhspencer