Class NullNode

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

public class NullNode extends ValueNode
This singleton value class is used to contain explicit JSON null value.
See Also:
  • Field Details

    • instance

      public static final NullNode instance
  • Constructor Details

    • NullNode

      protected NullNode()
  • Method Details

    • getInstance

      public static NullNode getInstance()
    • readResolve

      protected Object readResolve()
    • 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
    • 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 ValueNode
    • deepCopy

      public NullNode deepCopy()
      Description copied from class: ValueNode
      All current value nodes are immutable, so we can just return them as is.
      Overrides:
      deepCopy in class ValueNode
      Returns:
      Node that is either a copy of this node (and all non-leaf children); or, for immutable leaf nodes, node itself.
    • _asBoolean

      protected Boolean _asBoolean()
      Description copied from class: BaseJsonNode
      Method sub-classes should override if they can produce boolean values via BaseJsonNode.asBoolean() -- if not, return null (in which case appropriate error will be thrown or default value returned).
      Overrides:
      _asBoolean in class BaseJsonNode
      Returns:
      Coerced value if possible; otherwise null to indicate this node cannot be coerced.
    • 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 or coercing null (or missing node), will return the specified default value.
      Overrides:
      asBoolean in class BaseJsonNode
    • asBooleanOpt

      public Optional<Boolean> asBooleanOpt()
      Description copied from class: JsonNode
      Similar to JsonNode.asBoolean(), but instead of throwing an exception for non-coercible values or coercing null (or missing node), will return Optional.empty().
      Overrides:
      asBooleanOpt in class BaseJsonNode
    • _asString

      protected String _asString()
      Description copied from class: BaseJsonNode
      Method sub-classes should override if they can produce String values via BaseJsonNode.asString() -- if not, return null (in which case appropriate error will be thrown or default value returned).
      Overrides:
      _asString in class BaseJsonNode
      Returns:
      Coerced value if possible; otherwise null to indicate this node cannot be coerced.
    • 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 or coercing null (or missing value), will return the specified default value.
      Overrides:
      asString in class BaseJsonNode
    • asStringOpt

      public Optional<String> asStringOpt()
      Description copied from class: JsonNode
      Similar to JsonNode.asString(), but instead of throwing an exception for non-coercible values or coercing null (or missing value), will return Optional.empty().
      Overrides:
      asStringOpt in class BaseJsonNode
    • 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 or null value: if not, a JsonNodeException will be thrown. In case of JSON null, Java null is returned.

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

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

      Overrides:
      stringValue in class BaseJsonNode
      Returns:
      String value this node represents (if JSON String), null for JSON null
    • 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. This default value case includes JSON null.
      Overrides:
      stringValue in class BaseJsonNode
      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 -- only returns null if defaultValue is null
    • 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 (NOTE: JSON null is not considered a String here)
      Overrides:
      stringValueOpt in class BaseJsonNode
      Returns:
      Optional<String> value (if node represents JSON String); Optional.empty() otherwise (including for JSON null)
    • 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
    • _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
    • 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
    • serialize

      public final void serialize(tools.jackson.core.JsonGenerator g, SerializationContext provider) 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
    • 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