Class MissingNode

All Implemented Interfaces:
Serializable, Iterable<JsonNode>, 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 TreeNode
      Overrides:
      isMissingNode in class BaseJsonNode
    • asToken

      public 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 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
    • 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 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 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 TreeNode
      Specified by:
      path in class JsonNode
    • _at

      protected JsonNode _at(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(JsonGenerator g, SerializationContext provider) throws 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:
      JacksonException
    • serializeWithType

      public void serializeWithType(JsonGenerator g, SerializationContext provider, TypeSerializer typeSer) throws 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:
      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