Class BaseJsonNode

All Implemented Interfaces:
Serializable, Iterable<JsonNode>, TreeNode, JacksonSerializable
Direct Known Subclasses:
ContainerNode, MissingNode, 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 JacksonSerializable. This simplifies object mapping aspects a bit, as no external serializers are needed.

Note that support for Serializable is added here and so all subtypes are fully JDK serializable: but also note that serialization is as JSON and should only be used for interoperability purposes where other approaches are not available.

See Also:
  • Field Details

  • Constructor Details

    • BaseJsonNode

      protected BaseJsonNode()
  • Method Details

    • isMissingNode

      public boolean isMissingNode()
      Specified by:
      isMissingNode in interface TreeNode
      Overrides:
      isMissingNode in class JsonNode
    • isEmbeddedValue

      public boolean isEmbeddedValue()
      Specified by:
      isEmbeddedValue in interface TreeNode
    • numberValue

      public Number numberValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as Number that accurately represents its value, if (and only if) this is a number node (returns true for JsonNode.isNumber()). If this node is NOT a number node, a JsonNodeException will be thrown.
      Specified by:
      numberValue in class JsonNode
      Returns:
      Number value this node contains, if numeric node
    • shortValue

      public short shortValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as 16-bit signed integer value (Java short): but if node value cannot be expressed exactly as a short, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Integer values that fit in Java 16-bit signed short range
      • JSON Floating-point values that fit in Java 16-bit signed short range AND do not have fractional part.

      Specified by:
      shortValue in class JsonNode
      Returns:
      Short value this node represents, if possible to accurately represent
    • intValue

      public int intValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java int: but if node value cannot be expressed exactly as an int, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Integer values that fit in Java 32-bit signed int range
      • JSON Floating-point values that fit in Java 32-bit signed int range AND do not have fractional part.

      NOTE: for more lenient conversions, use JsonNode.asInt()

      Specified by:
      intValue in class JsonNode
      Returns:
      Int value this node represents, if possible to accurately represent
    • intValue

      public int intValue(int defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.intValue(), but that will return specified defaultValue if this node cannot be converted to Java int.
      Specified by:
      intValue in class JsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to Java int
      Returns:
      Java int value this node represents, if possible to accurately represent; defaultValue otherwise
    • intValueOpt

      public OptionalInt intValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.intValue(), but that will return empty OptionalInt (OptionalInt.empty()) if this node cannot be converted to Java int.
      Specified by:
      intValueOpt in class JsonNode
      Returns:
      Java int value this node represents, as OptionalInt, if possible to accurately represent; OptionalInt.empty() otherwise
    • asInt

      public int asInt()
      Description copied from class: JsonNode
      Method similar to JsonNode.intValue() but in addition to coercing Number values (same as JsonNode.intValue()), will also try to coerce a couple of additional types (or cases):
      • JSON Floating-point numbers with fractions (ones without fractions are ok for JsonNode.intValue()) will be truncated to int (if (and only if) they fit in int range).
      • JSON Strings that represent JSON Numbers ("stringified" numbers)
      • JSON Null (converted to 0))
      • POJO nodes that contain Number values
      Specified by:
      asInt in class JsonNode
      Returns:
      int value this node represents, if possible to accurately represent
    • asInt

      public int asInt(int defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.intValue(), but that will return specified defaultValue if this node cannot be converted to int.
      Specified by:
      asInt in class JsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to int
      Returns:
      int value this node represents, if possible to accurately represent; defaultValue otherwise
    • asIntOpt

      public OptionalInt asIntOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asInt(), but that will return (OptionalInt.empty()) if this node cannot be coerced to int.
      Specified by:
      asIntOpt in class JsonNode
      Returns:
      OptionalInt value this node represents, if possible to accurately represent; OptionalInt.empty() otherwise
    • longValue

      public long longValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java long: but if node value cannot be expressed exactly as a long, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Integer values that fit in Java 64-bit signed long range
      • JSON Floating-point values that fit in Java 64-bit signed long range AND do not have fractional part.

      NOTE: for more lenient conversions, use JsonNode.asLong()

      Specified by:
      longValue in class JsonNode
      Returns:
      Long value this node represents, if possible to accurately represent
    • longValue

      public long longValue(long defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.longValue(), but that will return specified defaultValue if this node cannot be converted to long.
      Specified by:
      longValue in class JsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to long
      Returns:
      long value this node represents, if possible to accurately represent; defaultValue otherwise
    • longValueOpt

      public OptionalLong longValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.longValue(), but that will return empty OptionalLong (OptionalLong.empty()) if this node cannot be converted to Java long.
      Specified by:
      longValueOpt in class JsonNode
      Returns:
      Java long value this node represents, as OptionalLong, if possible to accurately represent; OptionalLong.empty() otherwise
    • asLong

      public long asLong()
      Description copied from class: JsonNode
      Method similar to JsonNode.longValue() but in addition to coercing Number values (same as JsonNode.longValue()), will also try to coerce a couple of additional types (or cases):
      • JSON Floating-point numbers with fractions (ones without fractions are ok for JsonNode.longValue()) will be truncated to long (if (and only if) they fit in long range).
      • JSON Strings that represent JSON Numbers ("stringified" numbers)
      • JSON Null (converted to 0))
      • POJO nodes that contain Number values
      Specified by:
      asLong in class JsonNode
      Returns:
      long value this node represents, if possible to accurately represent
    • asLong

      public long asLong(long defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.asLong(), but that will return specified defaultValue if this node cannot be coerced to long (instead of throwing an exception).
      Specified by:
      asLong in class JsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be coerced to long
      Returns:
      long value this node represents, if possible to accurately represent; defaultValue otherwise
    • asLongOpt

      public OptionalLong asLongOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asLong(), but that will return (OptionalLong.empty()) if this node cannot be coerced to long.
      Specified by:
      asLongOpt in class JsonNode
      Returns:
      OptionalLong value this node represents (or can be coerced to), OptionalLong.empty() otherwise
    • bigIntegerValue

      public BigInteger bigIntegerValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a BigInteger, but if node value cannot be expressed exactly as a BigInteger, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Integer values
      • JSON Floating-point values that do not have fractional part.

      Specified by:
      bigIntegerValue in class JsonNode
      Returns:
      BigInteger value this node represents, if possible to accurately represent
    • bigIntegerValue

      public BigInteger bigIntegerValue(BigInteger defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.bigIntegerValue(), but that will return specified defaultValue if this node cannot be converted to Java BigInteger.
      Specified by:
      bigIntegerValue in class JsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to Java BigInteger
      Returns:
      Java BigInteger value this node represents, if possible to accurately represent; defaultValue otherwise
    • bigIntegerValueOpt

      public Optional<BigInteger> bigIntegerValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.bigIntegerValue(), but that will return empty (Optional.empty()) if this node cannot be converted to Java BigInteger.
      Specified by:
      bigIntegerValueOpt in class JsonNode
      Returns:
      Java BigInteger value this node represents, as Optional<BigInteger>, if possible to accurately represent; Optional.empty() otherwise
    • asBigInteger

      public BigInteger asBigInteger()
      Description copied from class: JsonNode
      Method similar to JsonNode.bigIntegerValue() but in addition to coercing Number values (same as JsonNode.bigIntegerValue()), will also try to coerce a couple of additional types (or cases):
      • JSON Floating-point numbers with fractions (ones without fractions are ok for JsonNode.bigIntegerValue()) will be truncated to integer value (like with BigDecimal.toBigInteger()))
      • JSON Strings that represent JSON Numbers ("stringified" numbers)
      • JSON Null (converted to 0))
      • POJO nodes that contain Number values
      Specified by:
      asBigInteger in class JsonNode
      Returns:
      BigInteger value this node represents, if possible to accurately convert; defaultValue otherwise
    • asBigInteger

      public BigInteger asBigInteger(BigInteger defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.asBigInteger(), but that will return specified defaultValue if this node cannot be converted to BigInteger.
      Specified by:
      asBigInteger in class JsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to BigInteger
      Returns:
      BigInteger value this node represents, if possible to accurately convert; defaultValue otherwise
    • asBigIntegerOpt

      public Optional<BigInteger> asBigIntegerOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.bigIntegerValue(), but that will return empty (Optional.empty()) if this node cannot be converted to Java BigInteger.
      Specified by:
      asBigIntegerOpt in class JsonNode
      Returns:
      BigInteger value this node represents, as Optional<BigInteger>, if possible to accurately represent; Optional.empty() otherwise.
    • floatValue

      public float floatValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java float: but if node value cannot be expressed exactly as a float, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Floating-point values that fit in Java 32-bit double range
      • JSON Integer values that fit in Java 32-bit double range

      Specified by:
      floatValue in class JsonNode
      Returns:
      Float value this node represents, if possible to accurately represent
    • doubleValue

      public double doubleValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a double: but if node value cannot be expressed exactly as a double, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Floating-point values that fit in Java 64-bit double range
      • JSON Integer values that fit in Java 64-bit double range

      NOTE: for more lenient conversions, use JsonNode.asDouble()

      Specified by:
      doubleValue in class JsonNode
      Returns:
      Double value this node represents, if possible to accurately represent
    • doubleValue

      public double doubleValue(double defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.doubleValue(), but that will return specified defaultValue if this node cannot be converted to double.
      Specified by:
      doubleValue in class JsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to double
      Returns:
      double value this node represents, if possible to accurately represent; defaultValue otherwise
    • doubleValueOpt

      public OptionalDouble doubleValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.doubleValue(), but that will return empty OptionalLong (OptionalDouble.empty()) if this node cannot be converted to Java double.
      Specified by:
      doubleValueOpt in class JsonNode
      Returns:
      Java double value this node represents, as OptionalDouble, if possible to accurately represent; OptionalDouble.empty() otherwise
    • asDouble

      public double asDouble()
      Description copied from class: JsonNode
      Method similar to JsonNode.doubleValue() but in addition to coercing Number values will also try coerce couple of additional types:
      • JSON String that represents JSON Numbers ("stringified" numbers)
      • JSON Null (converted to 0.0d)
      • POJO nodes that contain Number values

      Specified by:
      asDouble in class JsonNode
      Returns:
      double value this node represents, if possible to accurately represent
    • asDouble

      public double asDouble(double defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.asDouble(), but that will return defaultValue if this node cannot be coerced to double.
      Specified by:
      asDouble in class JsonNode
      Returns:
      double value this node represents, if possible to accurately represent; defaultValue otherwise
    • asDoubleOpt

      public OptionalDouble asDoubleOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asDouble(), but that will return (OptionalDouble.empty()) if this node cannot be coerced to double.
      Specified by:
      asDoubleOpt in class JsonNode
      Returns:
      OptionalDouble value this node represents, if possible to accurately represent; OptionalDouble.empty() otherwise
    • decimalValue

      public BigDecimal decimalValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java BigDecimal: but if node value cannot be expressed exactly as a BigDecimal, a JsonNodeException will be thrown. Access works for following cases:
      • All JSON Number values

      NOTE: for more lenient conversions, use JsonNode.asDecimal()

      Specified by:
      decimalValue in class JsonNode
      Returns:
      BigDecimal value this node represents, if possible to accurately represent
    • decimalValue

      public BigDecimal decimalValue(BigDecimal defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.decimalValue(), but that will return defaultValue if this node cannot be coerced to Java BigDecimal.
      Specified by:
      decimalValue in class JsonNode
      Returns:
      BigDecimal value this node represents, if possible to accurately represent; defaultValue otherwise
    • decimalValueOpt

      public Optional<BigDecimal> decimalValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.decimalValue(), but that will return empty Optional (Optional.empty()) if this node cannot be coerced to BigDecimal.
      Specified by:
      decimalValueOpt in class JsonNode
      Returns:
      Java BigDecimal value this node represents, as Optional<BigDecimal>, if possible to accurately represent; Optional.empty() otherwise
    • asDecimal

      public BigDecimal asDecimal()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a BigDecimal: but if node value cannot be expressed exactly as a BigDecimal, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Floating-point values (but not "NaN" or "Infinity")
      • JSON Integer values
      • JSON String that represents JSON Numbers ("stringified" numbers)
      • JSON Null (converted to BigDecimal.ZERO))
      • POJO nodes that contain Number values

      Specified by:
      asDecimal in class JsonNode
      Returns:
      BigDecimal value this node represents, if possible to accurately represent
    • asDecimal

      public BigDecimal asDecimal(BigDecimal defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.asDecimal(), but that will return defaultValue if this node cannot be coerced to Java BigDecimal.
      Specified by:
      asDecimal in class JsonNode
      Returns:
      BigDecimal value this node represents, if possible to accurately represent; defaultValue otherwise
    • asDecimalOpt

      public Optional<BigDecimal> asDecimalOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asDecimal(), but that will return empty Optional (Optional.empty()) if this node cannot be coerced to BigDecimal.
      Specified by:
      asDecimalOpt in class JsonNode
      Returns:
      Java BigDecimal value this node represents, as Optional<BigDecimal>, if possible to accurately represent; Optional.empty() otherwise
    • binaryValue

      public byte[] binaryValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as binary value (Java byte[]) which works if (and only if) node contains binary value (for JSON, Base64-encoded String, for other formats native binary value): if not, a JsonNodeException will be thrown. To check if this method can be used, you may call JsonNode.isBinary().

      Specified by:
      binaryValue in class JsonNode
      Returns:
      Binary value this node represents (if node contains binary value)
    • booleanValue

      public boolean booleanValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java boolean which works if (and only if) node contains JSON boolean value: if not, a JsonNodeException will be thrown.

      NOTE: for more lenient conversions, use JsonNode.asBoolean()

      Specified by:
      booleanValue in class JsonNode
      Returns:
      boolean value this node represents (if JSON boolean)
    • booleanValue

      public boolean booleanValue(boolean defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.booleanValue(), but that will return specified defaultValue if this node does not contain a JSON boolean.
      Specified by:
      booleanValue in class JsonNode
      Parameters:
      defaultValue - Value to return if this node does not contain a JSON boolean.
      Returns:
      Java boolean value this node represents (if JSON boolean); defaultValue otherwise
    • booleanValueOpt

      public Optional<Boolean> booleanValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.booleanValue(), but that will return Optional.empty() if this node does not contain a JSON boolean.
      Specified by:
      booleanValueOpt in class JsonNode
      Returns:
      Optional<Boolean> value (if node represents JSON boolean); Optional.empty() otherwise
    • asBoolean

      public boolean asBoolean()
      Description copied from class: JsonNode
      Method that will try to convert value of this node to a Java boolean. JSON Booleans map naturally; Integer numbers other than 0 map to true, and 0 maps to false; null maps to false and Strings 'true' and 'false' map to corresponding values. Other values (including structured types like Objects and Arrays) will result in a JsonNodeException being thrown.
      Specified by:
      asBoolean in class JsonNode
      Returns:
      Boolean value this node represents, if coercible; exception otherwise
    • asBoolean

      public boolean asBoolean(boolean defaultValue)
      Description copied from class: JsonNode
      Similar to JsonNode.asBoolean(), but instead of throwing an exception for non-coercible values, will return specified default value.
      Specified by:
      asBoolean in class JsonNode
    • asBooleanOpt

      public Optional<Boolean> asBooleanOpt()
      Description copied from class: JsonNode
      Similar to JsonNode.asBoolean(), but instead of throwing an exception for non-coercible values, will return Optional.empty().
      Specified by:
      asBooleanOpt in class JsonNode
    • stringValue

      public String stringValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java String which works if (and only if) node contains JSON String value: if not, a JsonNodeException will be thrown.

      NOTE: for more lenient conversions, use JsonNode.asString()

      NOTE: in Jackson 2.x, was textValue().

      Specified by:
      stringValue in class JsonNode
      Returns:
      String value this node represents (if JSON String)
    • stringValue

      public String stringValue(String defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.stringValue(), but that will return specified defaultValue if this node does not contain a JSON String.
      Specified by:
      stringValue in class JsonNode
      Parameters:
      defaultValue - Value to return if this node does not contain a JSON String.
      Returns:
      Java String value this node represents (if JSON String); defaultValue otherwise
    • stringValueOpt

      public Optional<String> stringValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.stringValue(), but that will return Optional.empty() if this node does not contain a JSON String.
      Specified by:
      stringValueOpt in class JsonNode
      Returns:
      Optional<String> value (if node represents JSON String); Optional.empty() otherwise
    • asString

      public String asString()
      Description copied from class: JsonNode
      Method that will try to convert value of this node to a String. JSON Strings map naturally; other scalars map to their string representation (including Binary data as Base64 encoded String); JSON nulls map to empty String. Other values (including structured types like Objects and Arrays, and "missing" value) will result in a JsonNodeException being thrown.

      NOTE: this is NOT same as JsonNode.toString() in that result is

      NOT VALID ENCODED JSON

      for all nodes (although is for some, like NumberNodes and BooleanNodes).
      Specified by:
      asString in class JsonNode
      Returns:
      String representation of this node, if coercible; exception otherwise
    • asString

      public String asString(String defaultValue)
      Description copied from class: JsonNode
      Similar to JsonNode.asString(), but instead of throwing an exception for non-coercible values, will return specified default value.
      Specified by:
      asString in class JsonNode
    • asStringOpt

      public Optional<String> asStringOpt()
      Description copied from class: JsonNode
      Similar to JsonNode.asString(), but instead of throwing an exception for non-coercible values, will return Optional.empty().
      Specified by:
      asStringOpt in class JsonNode
    • 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(propertyName).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 propertyName (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.
      Specified by:
      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.
      Specified by:
      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 JsonParser traverse(ObjectReadContext readCtxt)
      Specified by:
      traverse in interface TreeNode
    • asToken

      public abstract 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 TreeNode
    • numberType

      public 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 TreeNode
    • withObject

      public ObjectNode withObject(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(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)
    • _withXxxVerifyReplace

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

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

      public ArrayNode withArray(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(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)
    • _asBoolean

      protected Boolean _asBoolean()
      Method sub-classes should override if they can produce boolean values via asBoolean() -- if not, return null (in which case appropriate error will be thrown or default value returned).
      Returns:
      Coerced value if possible; otherwise null to indicate this node cannot be coerced.
    • _asString

      protected String _asString()
      Method sub-classes should override if they can produce String values via asString() -- if not, return null (in which case appropriate error will be thrown or default value returned).
      Returns:
      Coerced value if possible; otherwise null to indicate this node cannot be coerced.
    • serialize

      public abstract void serialize(JsonGenerator jgen, SerializationContext ctxt) throws JacksonException
      Method called to serialize node instances using given generator.
      Specified by:
      serialize in interface JacksonSerializable
      Throws:
      JacksonException
    • serializeWithType

      public abstract void serializeWithType(JsonGenerator jgen, SerializationContext ctxt, TypeSerializer typeSer) throws JacksonException
      Type information is needed, even if JsonNode instances are "plain" JSON, since they may be mixed with other types.
      Specified by:
      serializeWithType in interface JacksonSerializable
      Throws:
      JacksonException
    • 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
    • _reportCoercionFail

      protected <T> T _reportCoercionFail(String method, Class<?> targetType, String message)
    • _reportShortCoercionRangeFail

      protected short _reportShortCoercionRangeFail(String method)
    • _reportIntCoercionRangeFail

      protected int _reportIntCoercionRangeFail(String method)
    • _reportLongCoercionRangeFail

      protected long _reportLongCoercionRangeFail(String method)
    • _reportFloatCoercionRangeFail

      protected float _reportFloatCoercionRangeFail(String method)
    • _reportDoubleCoercionRangeFail

      protected double _reportDoubleCoercionRangeFail(String method)
    • _reportShortCoercionFractionFail

      protected short _reportShortCoercionFractionFail(String method)
    • _reportIntCoercionFractionFail

      protected int _reportIntCoercionFractionFail(String method)
    • _reportLongCoercionFractionFail

      protected long _reportLongCoercionFractionFail(String method)
    • _reportBigIntegerCoercionFractionFail

      protected BigInteger _reportBigIntegerCoercionFractionFail(String method)
    • _reportIntCoercionNaNFail

      protected int _reportIntCoercionNaNFail(String method)
    • _reportLongCoercionNaNFail

      protected long _reportLongCoercionNaNFail(String method)
    • _reportBigIntegerCoercionNaNFail

      protected BigInteger _reportBigIntegerCoercionNaNFail(String method)
    • _reportBigDecimalCoercionNaNFail

      protected BigDecimal _reportBigDecimalCoercionNaNFail(String method)
    • _reportWrongNodeType

      protected <T> T _reportWrongNodeType(String msgTemplate, Object... args)
      Helper method that throws JsonNodeException as a result of this node being of wrong type
    • _jsonPointerIfValid

      protected JsonPointer _jsonPointerIfValid(String exprOrProperty)
    • _valueDesc

      protected abstract String _valueDesc()
      Method for implementation classes to return a short description of contained value, to be used in error messages.