Class MissingNode

All Implemented Interfaces:
Serializable, Iterable<JsonNode>, tools.jackson.core.TreeNode, JacksonSerializable

public final class MissingNode extends BaseJsonNode
This singleton node class is generated to denote "missing nodes" along paths that do not exist. For example, if a path via element of an array is requested for an element outside range of elements in the array; or for a non-array value, result will be reference to this node.

In most respects this placeholder node will act as NullNode; for example, for purposes of value conversions, value is considered to be null and represented as value zero when used for numeric conversions.

See Also:
  • Constructor Details

    • MissingNode

      protected MissingNode()
  • Method Details

    • readResolve

      protected Object readResolve()
    • deepCopy

      public MissingNode deepCopy()
      Description copied from class: JsonNode
      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. This means it can either make a copy of this node (and all mutable children and grand children nodes), or node itself if it is immutable.

      Note: return type is guaranteed to have same type as the node method is called on; which is why method is declared with local generic type.

      Specified by:
      deepCopy in class JsonNode
      Returns:
      Node that is either a copy of this node (and all non-leaf children); or, for immutable leaf nodes, node itself.
    • getInstance

      public static MissingNode getInstance()
    • getNodeType

      public JsonNodeType getNodeType()
      Description copied from class: JsonNode
      Return the type of this node
      Specified by:
      getNodeType in class JsonNode
      Returns:
      the node type as a JsonNodeType enum value
    • isMissingNode

      public final boolean isMissingNode()
      Specified by:
      isMissingNode in interface tools.jackson.core.TreeNode
      Overrides:
      isMissingNode in class BaseJsonNode
    • asToken

      public tools.jackson.core.JsonToken asToken()
      Description copied from class: BaseJsonNode
      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 tools.jackson.core.TreeNode
      Specified by:
      asToken in class BaseJsonNode
    • _valueDesc

      protected String _valueDesc()
      Description copied from class: BaseJsonNode
      Method for implementation classes to return a short description of contained value, to be used in error messages.
      Specified by:
      _valueDesc in class BaseJsonNode
    • asBoolean

      public boolean asBoolean()
      Description copied from class: JsonNode
      Method that will try to convert or coerce 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 (and missing node) 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.
      Overrides:
      asBoolean in class BaseJsonNode
      Returns:
      Boolean value this node represents, if coercible; exception otherwise
    • asString

      public String asString()
      Description copied from class: JsonNode
      Method that will try to convert or coerce 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 and "missing nodes" map to empty String. Structured types like Objects and Arrays, 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).
      Overrides:
      asString in class BaseJsonNode
      Returns:
      String representation of this node, if coercible (scalar type); exception otherwise (structured type)
    • asShort

      public short asShort()
      Description copied from class: JsonNode
      Method similar to JsonNode.shortValue() but in addition to coercing Number values (same as JsonNode.shortValue()), 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.shortValue()) will be truncated to short (if (and only if) they fit in short range).
      • JSON Strings that represent JSON Numbers ("stringified" numbers)
      • JSON Null (coerced to 0))
      • Missing node (coerced to 0))
      • POJO nodes that contain Number values
      Overrides:
      asShort in class BaseJsonNode
      Returns:
      short value this node represents, if possible to accurately represent
    • 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 (coerced to 0))
      • Missing node (coerced to 0))
      • POJO nodes that contain Number values
      Overrides:
      asInt in class BaseJsonNode
      Returns:
      int value this node represents, if possible to accurately represent
    • 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 (coerced to 0))
      • Missing node (coerced to 0))
      • POJO nodes that contain Number values
      Overrides:
      asLong in class BaseJsonNode
      Returns:
      long value this node represents, if possible to accurately represent
    • 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 (coerced to BigInteger.ZERO))
      • Missing node (coerced to BigInteger.ZERO))
      • POJO nodes that contain Number values
      Overrides:
      asBigInteger in class BaseJsonNode
      Returns:
      BigInteger value this node represents, if possible to accurately convert; defaultValue otherwise
    • asFloat

      public float asFloat()
      Description copied from class: JsonNode
      Method similar to JsonNode.floatValue() 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 (coerced to 0.0f))
      • Missing node (coerced to 0.0f))
      • POJO nodes that contain Number values

      Overrides:
      asFloat in class BaseJsonNode
      Returns:
      float value this node represents, if possible to accurately represent
    • 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 (coerced to 0.0d))
      • Missing node (coerced to 0.0d))
      • POJO nodes that contain Number values

      Overrides:
      asDouble in class BaseJsonNode
      Returns:
      double value this node represents, if possible to accurately represent
    • 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 (coerced to BigDecimal.ZERO))
      • Missing node (coerced to BigDecimal.ZERO))
      • POJO nodes that contain Number values

      Overrides:
      asDecimal in class BaseJsonNode
      Returns:
      BigDecimal value this node represents, if possible to accurately represent
    • asOptional

      public Optional<JsonNode> asOptional()
      Description copied from class: JsonNode
      Method that will return a JsonNode wrapped in Java's Optional. All nodes except of MissingNode will return non-empty Optional; MissingNode will return empty Optional.
      Overrides:
      asOptional in class JsonNode
      Returns:
      Optional<JsonNode> containing this node, or Optional.empty() if this is a MissingNode.
    • require

      public JsonNode require()
      Description copied from class: JsonNode
      Method that may be called to verify that this node is NOT so-called "missing node": that is, one for which JsonNode.isMissingNode() returns true. If not missing node, this is returned to allow chaining; otherwise exception is thrown.
      Overrides:
      require in class JsonNode
      Returns:
      this node to allow chaining
    • requireNonNull

      public JsonNode requireNonNull()
      Description copied from class: JsonNode
      Method that may be called to verify that this node is neither so-called "missing node" (that is, one for which JsonNode.isMissingNode() returns true) nor "null node" (one for which JsonNode.isNull() returns true). If non-null non-missing node, this is returned to allow chaining; otherwise exception is thrown.
      Overrides:
      requireNonNull in class JsonNode
      Returns:
      this node to allow chaining
    • get

      public JsonNode get(int index)
      Description copied from class: JsonNode
      Method for accessing value of the specified element of an array node. For other nodes, null is always returned.

      For array nodes, index specifies exact location within array and allows for efficient iteration over child elements (underlying storage is guaranteed to be efficiently indexable, i.e. has random-access to elements). If index is less than 0, or equal-or-greater than node.size(), null is returned; no exception is thrown for any index.

      NOTE: if the element value has been explicitly set as null (which is different from removal!), a NullNode will be returned, not null.

      Specified by:
      get in interface tools.jackson.core.TreeNode
      Specified by:
      get in class JsonNode
      Returns:
      Node that represent value of the specified element, if this node is an array and has specified element. Null otherwise.
    • path

      public JsonNode path(String fieldName)
      Description copied from class: JsonNode
      This method is similar to JsonNode.get(String), except that instead of returning null if no such value exists (due to this node not being an object, or object not having value for the specified field), a "missing node" (node that returns true for JsonNode.isMissingNode()) will be returned. This allows for convenient and safe chained access via path calls.
      Specified by:
      path in interface tools.jackson.core.TreeNode
      Specified by:
      path in class JsonNode
    • path

      public JsonNode path(int index)
      Description copied from class: JsonNode
      This method is similar to JsonNode.get(int), except that instead of returning null if no such element exists (due to index being out of range, or this node not being an array), a "missing node" (node that returns true for JsonNode.isMissingNode()) will be returned. This allows for convenient and safe chained access via path calls.
      Specified by:
      path in interface tools.jackson.core.TreeNode
      Specified by:
      path in class JsonNode
    • _at

      protected JsonNode _at(tools.jackson.core.JsonPointer ptr)
      Description copied from class: JsonNode
      Helper method used by other methods for traversing the next step of given path expression, and returning matching value node if any: if no match, null is returned.
      Specified by:
      _at in class JsonNode
      Parameters:
      ptr - Path expression to use
      Returns:
      Either matching JsonNode for the first step of path or null if no match (including case that this node is not a container)
    • findValue

      public JsonNode findValue(String fieldName)
      Description copied from class: JsonNode
      Method for finding the first JSON Object field with specified name in this node or its child nodes, and returning value it has. If no matching field is found in this node or its descendants, returns null.

      Note that traversal is done in document order (that is, order in which nodes are iterated if using JsonNode.values())

      Specified by:
      findValue in class JsonNode
      Parameters:
      fieldName - Name of field to look for
      Returns:
      Value of first matching node found, if any; null if none
    • findParent

      public JsonNode findParent(String fieldName)
      Description copied from class: JsonNode
      Method for finding a JSON Object that contains specified field, within this node or its descendants. If no matching field is found in this node or its descendants, returns null.
      Specified by:
      findParent in class JsonNode
      Parameters:
      fieldName - Name of field to look for
      Returns:
      Value of first matching node found, if any; null if none
    • findValues

      public List<JsonNode> findValues(String fieldName, List<JsonNode> foundSoFar)
      Specified by:
      findValues in class JsonNode
    • findValuesAsString

      public List<String> findValuesAsString(String fieldName, List<String> foundSoFar)
      Specified by:
      findValuesAsString in class JsonNode
    • findParents

      public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
      Specified by:
      findParents in class JsonNode
    • serialize

      public final void serialize(tools.jackson.core.JsonGenerator g, SerializationContext ctxt) throws tools.jackson.core.JacksonException
      Description copied from class: BaseJsonNode
      Method called to serialize node instances using given generator.
      Specified by:
      serialize in interface JacksonSerializable
      Specified by:
      serialize in class BaseJsonNode
      Throws:
      tools.jackson.core.JacksonException
    • serializeWithType

      public void serializeWithType(tools.jackson.core.JsonGenerator g, SerializationContext ctxt, TypeSerializer typeSer) throws tools.jackson.core.JacksonException
      Description copied from class: BaseJsonNode
      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
      Specified by:
      serializeWithType in class BaseJsonNode
      Throws:
      tools.jackson.core.JacksonException
    • equals

      public boolean equals(Object o)
      Description copied from class: JsonNode
      Equality for node objects is defined as full (deep) value equality. This means that it is possible to compare complete JSON trees for equality by comparing equality of root nodes.

      Note: marked as abstract to ensure all implementation classes define it properly and not rely on definition from Object.

      Specified by:
      equals in class JsonNode
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class BaseJsonNode
    • 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.

      Overrides:
      toString in class BaseJsonNode
    • 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 BaseJsonNode