com.fasterxml.jackson.databind.node

## Class BaseJsonNode

- java.lang.Object
- - com.fasterxml.jackson.databind.JsonSerializable.Base
  - - com.fasterxml.jackson.databind.JsonNode
    - - com.fasterxml.jackson.databind.node.BaseJsonNode

All Implemented Interfaces:
  com.fasterxml.jackson.core.TreeNode, JsonSerializable, Serializable, Iterable<JsonNode>

Direct Known Subclasses:
  ContainerNode, ValueNode

    public abstract class BaseJsonNode
    extends JsonNode
    implements Serializable

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 `Serializable`.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonNode

`JsonNode.OverwriteMode`

### Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.JsonSerializable

`JsonSerializable.Base`

### Constructor Summary

Constructors
`protected` `BaseJsonNode()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`protected BigInteger` `_bigIntFromBigDec(BigDecimal value)`
`protected com.fasterxml.jackson.core.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(com.fasterxml.jackson.core.JsonPointer origPtr, com.fasterxml.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)`
`protected ObjectNode` `_withObject(com.fasterxml.jackson.core.JsonPointer origPtr, com.fasterxml.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)`
`protected boolean` `_withXxxMayReplace(JsonNode node, JsonNode.OverwriteMode overwriteMode)`
`protected void` `_withXxxVerifyReplace(com.fasterxml.jackson.core.JsonPointer origPtr, com.fasterxml.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex, JsonNode toReplace)`
`abstract com.fasterxml.jackson.core.JsonToken` `asToken()` Method that can be used for efficient type detection when using stream abstraction for traversing nodes.
`JsonNode` `findPath(String fieldName)` Method similar to `JsonNode.findValue(java.lang.String)`, but that will return a "missing node" instead of null if no field is found.
`abstract int` `hashCode()`
`com.fasterxml.jackson.core.JsonParser.NumberType` `numberType()` Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.
`JsonNode` `required(int index)` 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).
`JsonNode` `required(String fieldName)` 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).
`abstract void` `serialize(com.fasterxml.jackson.core.JsonGenerator g, SerializerProvider ctxt)` Method called to serialize node instances using given generator.
`abstract void` `serializeWithType(com.fasterxml.jackson.core.JsonGenerator g, SerializerProvider ctxt, TypeSerializer typeSer)` Type information is needed, even if JsonNode instances are "plain" JSON, since they may be mixed with other types.
`String` `toPrettyString()` Alternative to `JsonNode.toString()` that will serialize this node using Jackson default pretty-printer.
`String` `toString()` Method that will produce (as of Jackson 2.10) valid JSON using default settings of databind, as String.
`com.fasterxml.jackson.core.JsonParser` `traverse()`
`com.fasterxml.jackson.core.JsonParser` `traverse(com.fasterxml.jackson.core.ObjectCodec codec)`
`ArrayNode` `withArray(com.fasterxml.jackson.core.JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)` 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.
`ObjectNode` `withObject(com.fasterxml.jackson.core.JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)` 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.

### Methods inherited from class com.fasterxml.jackson.databind.JsonNode

`_at, _reportRequiredViolation, _this, asBoolean, asBoolean, asDouble, asDouble, asInt, asInt, asLong, asLong, asOptional, asText, asText, at, at, bigIntegerValue, binaryValue, booleanValue, canConvertToExactIntegral, canConvertToInt, canConvertToLong, decimalValue, deepCopy, doubleValue, elements, equals, equals, fieldNames, fields, findParent, findParents, findParents, findValue, findValues, findValues, findValuesAsText, findValuesAsText, floatValue, forEachEntry, get, get, getNodeType, has, has, hasNonNull, hasNonNull, intValue, isArray, isBigDecimal, isBigInteger, isBinary, isBoolean, isContainerNode, isDouble, isEmpty, isFloat, isFloatingPointNumber, isInt, isIntegralNumber, isLong, isMissingNode, isNull, isNumber, isObject, isPojo, isShort, isTextual, isValueNode, iterator, longValue, numberValue, optional, optional, path, path, properties, propertyStream, require, requiredAt, requiredAt, requireNonNull, shortValue, size, textValue, values, valueStream, with, withArray, withArray, withArray, withArrayProperty, withObject, withObject, withObject, withObjectProperty`

### Methods inherited from class com.fasterxml.jackson.databind.JsonSerializable.Base

`isEmpty`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Constructor Detail

#### BaseJsonNode

    protected BaseJsonNode()

### Method Detail

#### findPath

    public final JsonNode findPath(String fieldName)

Description copied from class: `JsonNode`
Method similar to `JsonNode.findValue(java.lang.String)`, 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 `JsonNode.isMissingNode()` returns true; and all value access methods return empty or missing value.

Specified by:
  `findPath` in class `JsonNode`
Parameters:
  `fieldName` - Name of field to look for
Returns:
  Value of first matching node found; or if not found, a "missing node" (non-null instance that has no value)

#### hashCode

    public abstract int hashCode()

Overrides:
  `hashCode` in class `Object`

#### required

    public JsonNode required(String fieldName)

Description copied from class: `JsonNode`
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.

Overrides:
  `required` in class `JsonNode`
Parameters:
  `fieldName` - Name of property to access
Returns:
  Value of the specified property of this Object node

#### required

    public JsonNode required(int index)

Description copied from class: `JsonNode`
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.

Overrides:
  `required` in class `JsonNode`
Parameters:
  `index` - Index of the value of this Array node to access
Returns:
  Value at specified index of this Array node

#### traverse

    public com.fasterxml.jackson.core.JsonParser traverse()

Specified by:
  `traverse` in interface `com.fasterxml.jackson.core.TreeNode`

#### traverse

    public com.fasterxml.jackson.core.JsonParser traverse(com.fasterxml.jackson.core.ObjectCodec codec)

Specified by:
  `traverse` in interface `com.fasterxml.jackson.core.TreeNode`

#### asToken

    public abstract com.fasterxml.jackson.core.JsonToken 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)

Specified by:
  `asToken` in interface `com.fasterxml.jackson.core.TreeNode`

#### numberType

    public com.fasterxml.jackson.core.JsonParser.NumberType numberType()

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

Specified by:
  `numberType` in interface `com.fasterxml.jackson.core.TreeNode`

#### withObject

    public ObjectNode withObject(com.fasterxml.jackson.core.JsonPointer ptr,
                                 JsonNode.OverwriteMode overwriteMode,
                                 boolean preferIndex)

Description copied from class: `JsonNode`
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.

Overrides:
  `withObject` in class `JsonNode`
Parameters:
  `ptr` - Pointer that indicates path to use for `ObjectNode` value to return (potentially creating one as necessary)
  `overwriteMode` - Defines which node types may be converted in case of incompatible `JsonPointer` expression: if conversion not allowed, `UnsupportedOperationException` is thrown.
  `preferIndex` - 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` found or created

#### _withObject

    protected ObjectNode _withObject(com.fasterxml.jackson.core.JsonPointer origPtr,
                                     com.fasterxml.jackson.core.JsonPointer currentPtr,
                                     JsonNode.OverwriteMode overwriteMode,
                                     boolean preferIndex)

#### _withXxxVerifyReplace

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

#### _withXxxMayReplace

    protected boolean _withXxxMayReplace(JsonNode node,
                                         JsonNode.OverwriteMode overwriteMode)

#### withArray

    public ArrayNode withArray(com.fasterxml.jackson.core.JsonPointer ptr,
                               JsonNode.OverwriteMode overwriteMode,
                               boolean preferIndex)

Description copied from class: `JsonNode`
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.

Overrides:
  `withArray` in class `JsonNode`
Parameters:
  `ptr` - Pointer that indicates path to use for `ArrayNode` value to return (potentially creating it as necessary)
  `overwriteMode` - Defines which node types may be converted in case of incompatible `JsonPointer` expression: if conversion not allowed, an exception is thrown.
  `preferIndex` - 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` found or created

#### _withArray

    protected ArrayNode _withArray(com.fasterxml.jackson.core.JsonPointer origPtr,
                                   com.fasterxml.jackson.core.JsonPointer currentPtr,
                                   JsonNode.OverwriteMode overwriteMode,
                                   boolean preferIndex)

#### serialize

    public abstract void serialize(com.fasterxml.jackson.core.JsonGenerator g,
                                   SerializerProvider ctxt)
                            throws IOException

Method called to serialize node instances using given generator.

Specified by:
  `serialize` in interface `JsonSerializable`
Throws:
  `IOException`

#### serializeWithType

    public abstract void serializeWithType(com.fasterxml.jackson.core.JsonGenerator g,
                                           SerializerProvider ctxt,
                                           TypeSerializer typeSer)
                                    throws IOException

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

Specified by:
  `serializeWithType` in interface `JsonSerializable`
Throws:
  `IOException`

#### toString

    public String toString()

Description copied from class: `JsonNode`
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.

Specified by:
  `toString` in class `JsonNode`

#### toPrettyString

    public String toPrettyString()

Description copied from class: `JsonNode`
Alternative to `JsonNode.toString()` that will serialize this node using Jackson default pretty-printer.

Overrides:
  `toPrettyString` in class `JsonNode`

#### _reportWrongNodeType

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

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

#### _reportWrongNodeOperation

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

#### _jsonPointerIfValid

    protected com.fasterxml.jackson.core.JsonPointer _jsonPointerIfValid(String exprOrProperty)

#### _bigIntFromBigDec

    protected BigInteger _bigIntFromBigDec(BigDecimal value)