Top Description Fields Constructors Methods
com.fasterxml.jackson.databind.node

public abstract Class BaseJsonNode

extends JsonNode
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
com.fasterxml.jackson.databind.node.ContainerNode, com.fasterxml.jackson.databind.node.ValueNode
Imports
java.io.IOException, java.math.BigDecimal, .BigInteger, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.exc.StreamConstraintsException, com.fasterxml.jackson.databind.JsonNode, .JsonSerializable, .SerializerProvider, com.fasterxml.jackson.databind.jsontype.TypeSerializer, com.fasterxml.jackson.databind.util.ExceptionUtil

Abstract base class common to all standard JsonNode implementations. The main addition here is that we declare that sub-classes must implement JsonSerializable. This simplifies object mapping aspects a bit, as no external serializers are needed.

Since 2.10, all implements have been java.io.Serializable.

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected BigInteger
protected JsonPointer
_jsonPointerIfValid(String exprOrProperty)

protected <T> T
_reportWrongNodeOperation(String msgTemplate, Object... args)

protected <T> T
_reportWrongNodeType(String msgTemplate, Object... args)

Helper method that throws UnsupportedOperationException as a result of this node being of wrong type

protected ArrayNode
_withArray(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)

protected ObjectNode
_withObject(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)

protected boolean
protected void
_withXxxVerifyReplace(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex, JsonNode toReplace)

public abstract JsonToken
asToken()

Redeclares com.fasterxml.jackson.core.TreeNode.asToken.

Method that can be used for efficient type detection when using stream abstraction for traversing nodes.
public final JsonNode
findPath(String
Name of field to look for
fieldName
)

Implements abstract com.fasterxml.jackson.databind.JsonNode.findPath.

Method similar to findValue, but that will return a "missing node" instead of null if no field is found.
public abstract int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public JsonParser.NumberType
numberType()

Implements com.fasterxml.jackson.core.TreeNode.numberType.

Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.
public JsonNode
required(String
Name of property to access
fieldName
)

Overrides com.fasterxml.jackson.databind.JsonNode.required.

Method is functionally equivalent to path(fieldName).required() and can be used to check that this node is an ObjectNode (that is, represents JSON Object value) and has value for specified property with key fieldName (but note that value may be explicit JSON null value).
public JsonNode
required(int
Index of the value of this Array node to access
index
)

Overrides com.fasterxml.jackson.databind.JsonNode.required.

Method is functionally equivalent to path(index).required() and can be used to check that this node is an ArrayNode (that is, represents JSON Array value) and has value for specified index (but note that value may be explicit JSON null value).
public abstract void
serialize(JsonGenerator g, SerializerProvider ctxt)

Redeclares com.fasterxml.jackson.databind.JsonSerializable.serialize.

Method called to serialize node instances using given generator.
public abstract void
serializeWithType(JsonGenerator g, SerializerProvider ctxt, TypeSerializer typeSer)

Redeclares com.fasterxml.jackson.databind.JsonSerializable.serializeWithType.

Type information is needed, even if JsonNode instances are "plain" JSON, since they may be mixed with other types.
public String
toPrettyString()

Overrides com.fasterxml.jackson.databind.JsonNode.toPrettyString.

Alternative to toString that will serialize this node using Jackson default pretty-printer.
public String
toString()

Implements abstract com.fasterxml.jackson.databind.JsonNode.toString.

Method that will produce (as of Jackson 2.10) valid JSON using default settings of databind, as String.
public JsonParser
traverse()

Implements com.fasterxml.jackson.core.TreeNode.traverse.

Method for constructing a JsonParser instance for iterating over contents of the tree that this node is root of.
public JsonParser
traverse(ObjectCodec
ObjectCodec to associate with parser constructed
codec
)

Implements com.fasterxml.jackson.core.TreeNode.traverse.

Same as traverse(), but additionally passes com.fasterxml.jackson.core.ObjectCodec to use if JsonParser#readValueAs(Class) is used (otherwise caller must call JsonParser#setCodec on response explicitly).
public ArrayNode
withArray(JsonPointer
Pointer that indicates path to use for ArrayNode value to return (potentially creating it as necessary)
ptr
,
JsonNode.OverwriteMode
Defines which node types may be converted in case of incompatible JsonPointer expression: if conversion not allowed, an exception is thrown.
overwriteMode
,
boolean
When creating a path (for empty or replacement), and path contains segment that may be an array index (simple integer number like 3), whether to construct an ArrayNode (true) or ObjectNode (false). In latter case matching property with quoted number (like "3") is used within Object.
preferIndex
)

Overrides com.fasterxml.jackson.databind.JsonNode.withArray.

Method that can be called on Object or Array nodes, to access a Array-valued node pointed to by given JsonPointer, if such a node exists: or if not, an attempt is made to create one and return it.
public ObjectNode
withObject(JsonPointer
Pointer that indicates path to use for ObjectNode value to return (potentially creating one as necessary)
ptr
,
JsonNode.OverwriteMode
Defines which node types may be converted in case of incompatible JsonPointer expression: if conversion not allowed, UnsupportedOperationException is thrown.
overwriteMode
,
boolean
When creating a path (for empty or replacement), and path contains segment that may be an array index (simple integer number like 3), whether to construct an ArrayNode (true) or ObjectNode (false). In latter case matching property with quoted number (like "3") is used within Object.
preferIndex
)

Overrides com.fasterxml.jackson.databind.JsonNode.withObject.

Method that can be called on Object or Array nodes, to access a Object-valued node pointed to by given JsonPointer, if such a node exists: or if not, an attempt is made to create one and return it.
pack-priv Object
Inherited from com.fasterxml.jackson.databind.JsonNode:
_at_reportRequiredViolation_thisasBooleanasBooleanasDoubleasDoubleasIntasIntasLongasLongasTextasTextatatbigIntegerValuebinaryValuebooleanValuecanConvertToExactIntegralcanConvertToIntcanConvertToLongdecimalValuedeepCopydoubleValueelementsequalsequalsfieldNamesfieldsfindParentfindParentsfindParentsfindValuefindValuesfindValuesfindValuesAsTextfindValuesAsTextfloatValuegetgetgetNodeTypehashashasNonNullhasNonNullintValueisArrayisBigDecimalisBigIntegerisBinaryisBooleanisContainerNodeisDoubleisEmptyisFloatisFloatingPointNumberisIntisIntegralNumberisLongisMissingNodeisNullisNumberisObjectisPojoisShortisTextualisValueNodeiteratorlongValuenumberValuepathpathpropertiesrequirerequiredAtrequiredAtrequireNonNullshortValuesizetextValuewithwithArraywithArraywithArraywithArrayPropertywithObjectwithObjectwithObjectwithObjectProperty

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

BaseJsonNodeback to summary
protected BaseJsonNode()

Method Detail

_bigIntFromBigDecback to summary
protected BigInteger _bigIntFromBigDec(BigDecimal value)
_jsonPointerIfValidback to summary
protected JsonPointer _jsonPointerIfValid(String exprOrProperty)
_reportWrongNodeOperationback to summary
protected <T> T _reportWrongNodeOperation(String msgTemplate, Object... args)
_reportWrongNodeTypeback to summary
protected <T> T _reportWrongNodeType(String msgTemplate, Object... args)

Helper method that throws UnsupportedOperationException as a result of this node being of wrong type

_withArrayback to summary
protected ArrayNode _withArray(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)
_withObjectback to summary
protected ObjectNode _withObject(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)
_withXxxMayReplaceback to summary
protected boolean _withXxxMayReplace(JsonNode node, JsonNode.OverwriteMode overwriteMode)
_withXxxVerifyReplaceback to summary
protected void _withXxxVerifyReplace(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex, JsonNode toReplace)
asTokenback to summary
public abstract JsonToken asToken()

Redeclares com.fasterxml.jackson.core.TreeNode.asToken.

Method that can be used for efficient type detection when using stream abstraction for traversing nodes. Will return the first JsonToken that equivalent stream event would produce (for most nodes there is just one token but for structured/container types multiple)

Returns:JsonToken

Doc from com.fasterxml.jackson.core.TreeNode.asToken.

JsonToken that is most closely associated with the node type

Annotations
@Override
findPathback to summary
public final JsonNode findPath(String fieldName)

Implements abstract com.fasterxml.jackson.databind.JsonNode.findPath.

Doc from com.fasterxml.jackson.databind.JsonNode.findPath.

Method similar to findValue, but that will return a "missing node" instead of null if no field is found. Missing node is a specific kind of node for which isMissingNode returns true; and all value access methods return empty or missing value.

Parameters
fieldName:String

Name of field to look for

Returns:JsonNode

Value of first matching node found; or if not found, a "missing node" (non-null instance that has no value)

Annotations
@Override
hashCodeback to summary
public abstract int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
numberTypeback to summary
public JsonParser.NumberType numberType()

Implements com.fasterxml.jackson.core.TreeNode.numberType.

Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.

Returns:JsonParser.NumberType

Doc from com.fasterxml.jackson.core.TreeNode.numberType.

Type of number contained, if any; or null if node does not contain numeric value.

Annotations
@Override
requiredback to summary
public JsonNode required(String fieldName)

Overrides com.fasterxml.jackson.databind.JsonNode.required.

Doc from com.fasterxml.jackson.databind.JsonNode.required.

Method is functionally equivalent to path(fieldName).required() and can be used to check that this node is an ObjectNode (that is, represents JSON Object value) and has value for specified property with key fieldName (but note that value may be explicit JSON null value). If this node is Object Node and has value for specified property, matching value is returned; otherwise IllegalArgumentException is thrown.

Parameters
fieldName:String

Name of property to access

Returns:JsonNode

Value of the specified property of this Object node

Annotations
@Override
requiredback to summary
public JsonNode required(int index)

Overrides com.fasterxml.jackson.databind.JsonNode.required.

Doc from com.fasterxml.jackson.databind.JsonNode.required.

Method is functionally equivalent to path(index).required() and can be used to check that this node is an ArrayNode (that is, represents JSON Array value) and has value for specified index (but note that value may be explicit JSON null value). If this node is Array Node and has value for specified index, value at index is returned; otherwise IllegalArgumentException is thrown.

Parameters
index:int

Index of the value of this Array node to access

Returns:JsonNode

Value at specified index of this Array node

Annotations
@Override
serializeback to summary
public abstract void serialize(JsonGenerator g, SerializerProvider ctxt) throws IOException

Redeclares com.fasterxml.jackson.databind.JsonSerializable.serialize.

Method called to serialize node instances using given generator.

Annotations
@Override
serializeWithTypeback to summary
public abstract void serializeWithType(JsonGenerator g, SerializerProvider ctxt, TypeSerializer typeSer) throws IOException

Redeclares com.fasterxml.jackson.databind.JsonSerializable.serializeWithType.

Type information is needed, even if JsonNode instances are "plain" JSON, since they may be mixed with other types.

Annotations
@Override
toPrettyStringback to summary
public String toPrettyString()

Overrides com.fasterxml.jackson.databind.JsonNode.toPrettyString.

Doc from com.fasterxml.jackson.databind.JsonNode.toPrettyString.

Alternative to toString that will serialize this node using Jackson default pretty-printer.

Annotations
@Override
toStringback to summary
public String toString()

Implements abstract com.fasterxml.jackson.databind.JsonNode.toString.

Doc from com.fasterxml.jackson.databind.JsonNode.toString.

Method that will produce (as of Jackson 2.10) valid JSON using default settings of databind, as String. If you want other kinds of JSON output (or output formatted using one of other Jackson-supported data formats) make sure to use ObjectMapper or ObjectWriter to serialize an instance, for example:

   String json = objectMapper.writeValueAsString(rootNode);

Note

method defined as abstract to ensure all implementation classes explicitly implement method, instead of relying on Object#toString() definition.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
traverseback to summary
public JsonParser traverse()

Implements com.fasterxml.jackson.core.TreeNode.traverse.

Doc from com.fasterxml.jackson.core.TreeNode.traverse.

Method for constructing a JsonParser instance for iterating over contents of the tree that this node is root of. Functionally equivalent to first serializing tree using ObjectCodec and then re-parsing but more efficient.

Note

constructed parser instance will NOT initially point to a token, so before passing it to deserializers, it is typically necessary to advance it to the first available token by calling JsonParser#nextToken().

Also note that calling this method will NOT pass ObjectCodec reference, so data-binding callback methods like JsonParser#readValueAs(Class) will not work with calling JsonParser#setCodec). It is often better to call traverse(ObjectCodec) to pass the codec explicitly.

Returns:JsonParser

JsonParser that will stream over contents of this node

Annotations
@Override
traverseback to summary
public JsonParser traverse(ObjectCodec codec)

Implements com.fasterxml.jackson.core.TreeNode.traverse.

Doc from com.fasterxml.jackson.core.TreeNode.traverse.

Same as traverse(), but additionally passes com.fasterxml.jackson.core.ObjectCodec to use if JsonParser#readValueAs(Class) is used (otherwise caller must call JsonParser#setCodec on response explicitly).

Note

constructed parser instance will NOT initially point to a token, so before passing it to deserializers, it is typically necessary to advance it to the first available token by calling JsonParser#nextToken().

Parameters
codec:ObjectCodec

ObjectCodec to associate with parser constructed

Returns:JsonParser

JsonParser that will stream over contents of this node

Annotations
@Override
withArrayback to summary
public ArrayNode withArray(JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)

Overrides com.fasterxml.jackson.databind.JsonNode.withArray.

Doc from com.fasterxml.jackson.databind.JsonNode.withArray.

Method that can be called on Object or Array nodes, to access a Array-valued node pointed to by given JsonPointer, if such a node exists: or if not, an attempt is made to create one and return it. For example, on document

  { "a" : {
       "b" : [ 1, 2 ]
    }
  }
calling method with JsonPointer of /a/b would return Array
  [ 1, 2 ]

In cases where path leads to "missing" nodes, a path is created. So, for example, on above document, and JsonPointer of /a/x an empty ArrayNode would be returned and the document would look like:

  { "a" : {
       "b" : [ 1, 2 ],
       "x" : [ ]
    }
  }
Finally, if the path is incompatible with the document -- there is an existing JsonNode through which expression cannot go -- a replacement is attempted if (and only if) conversion is allowed as per overwriteMode passed in. For example, with above document and expression of /a/b/0, conversion is allowed if passing OverwriteMode.SCALARS or OvewriteMode.ALL, and resulting document would look like:
  { "a" : {
       "b" : [ [ ], 2 ],
       "x" : [ ]
    }
  }
but if different modes (NONE or NULLS) is passed, an exception is thrown instead.
Parameters
ptr:JsonPointer

Pointer that indicates path to use for ArrayNode value to return (potentially creating it as necessary)

overwriteMode:JsonNode.OverwriteMode

Defines which node types may be converted in case of incompatible JsonPointer expression: if conversion not allowed, an exception is thrown.

preferIndex:boolean

When creating a path (for empty or replacement), and path contains segment that may be an array index (simple integer number like 3), whether to construct an ArrayNode (true) or ObjectNode (false). In latter case matching property with quoted number (like "3") is used within Object.

Returns:ArrayNode

ArrayNode found or created

Annotations
@Override
withObjectback to summary
public ObjectNode withObject(JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)

Overrides com.fasterxml.jackson.databind.JsonNode.withObject.

Doc from com.fasterxml.jackson.databind.JsonNode.withObject.

Method that can be called on Object or Array nodes, to access a Object-valued node pointed to by given JsonPointer, if such a node exists: or if not, an attempt is made to create one and return it. For example, on document

  { "a" : {
       "b" : {
          "c" : 13
       }
    }
  }
calling method with JsonPointer of /a/b would return ObjectNode
  { "c" : 13 }

In cases where path leads to "missing" nodes, a path is created. So, for example, on above document, and JsonPointer of /a/x an empty ObjectNode would be returned and the document would look like:

  { "a" : {
       "b" : {
          "c" : 13
       },
       "x" : { }
    }
  }
Finally, if the path is incompatible with the document -- there is an existing JsonNode through which expression cannot go -- a replacement is attempted if (and only if) conversion is allowed as per overwriteMode passed in. For example, with above document and expression of /a/b/c, conversion is allowed if passing OverwriteMode.SCALARS or OvewriteMode.ALL, and resulting document would look like:
  { "a" : {
       "b" : {
          "c" : { }
       },
       "x" : { }
    }
  }
but if different modes (NONE or NULLS) is passed, an exception is thrown instead.
Parameters
ptr:JsonPointer

Pointer that indicates path to use for ObjectNode value to return (potentially creating one as necessary)

overwriteMode:JsonNode.OverwriteMode

Defines which node types may be converted in case of incompatible JsonPointer expression: if conversion not allowed, UnsupportedOperationException is thrown.

preferIndex:boolean

When creating a path (for empty or replacement), and path contains segment that may be an array index (simple integer number like 3), whether to construct an ArrayNode (true) or ObjectNode (false). In latter case matching property with quoted number (like "3") is used within Object.

Returns:ObjectNode

ObjectNode found or created

Annotations
@Override
writeReplaceback to summary
pack-priv Object writeReplace()