What is the difference between ObjectNode and JsonNode in Jackson?

THIS USER NEEDS HELP picture THIS USER NEEDS HELP · Aug 1, 2016 · Viewed 28k times · Source

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?

Answer

bhspencer picture bhspencer · Aug 1, 2016

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.