Class NullNode

All Implemented Interfaces:
Serializable, Iterable<JsonNode>, 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 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 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.
    • _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.
    • 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 (converted to 0))
      • POJO nodes that contain Number values
      Overrides:
      asShort in class BaseJsonNode
      Returns:
      short value this node represents, if possible to accurately represent
    • asShort

      public short asShort(short defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.shortValue(), but that will return specified defaultValue if this node cannot be converted to short.
      Overrides:
      asShort in class BaseJsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to short
      Returns:
      short value this node represents, if possible to accurately represent; defaultValue otherwise
    • asShortOpt

      public Optional<Short> asShortOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asShort(), but that will return (Optional.empty()) if this node cannot be coerced to short.
      Overrides:
      asShortOpt in class BaseJsonNode
      Returns:
      Optional<Short> value this node represents, if possible to accurately represent; Optional.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
      Overrides:
      asInt in class BaseJsonNode
      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.
      Overrides:
      asInt in class BaseJsonNode
      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.
      Overrides:
      asIntOpt in class BaseJsonNode
      Returns:
      OptionalInt value this node represents, if possible to accurately represent; OptionalInt.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
      Overrides:
      asLong in class BaseJsonNode
      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).
      Overrides:
      asLong in class BaseJsonNode
      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.
      Overrides:
      asLongOpt in class BaseJsonNode
      Returns:
      OptionalLong value this node represents (or can be coerced to), OptionalLong.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
      Overrides:
      asBigInteger in class BaseJsonNode
      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.
      Overrides:
      asBigInteger in class BaseJsonNode
      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.
      Overrides:
      asBigIntegerOpt in class BaseJsonNode
      Returns:
      BigInteger value this node represents, as Optional<BigInteger>, if possible to accurately represent; Optional.empty() 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 (converted 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
    • asFloat

      public float asFloat(float defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.asFloat(), but that will return defaultValue if this node cannot be coerced to float.
      Overrides:
      asFloat in class BaseJsonNode
      Returns:
      float value this node represents, if possible to accurately represent; defaultValue otherwise
    • asFloatOpt

      public Optional<Float> asFloatOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asFloat(), but that will return (Optional.empty()) if this node cannot be coerced to float.
      Overrides:
      asFloatOpt in class BaseJsonNode
      Returns:
      Optional<Float> value this node represents, if possible to accurately represent; Optional.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

      Overrides:
      asDouble in class BaseJsonNode
      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.
      Overrides:
      asDouble in class BaseJsonNode
      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.
      Overrides:
      asDoubleOpt in class BaseJsonNode
      Returns:
      OptionalDouble value this node represents, if possible to accurately represent; OptionalDouble.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

      Overrides:
      asDecimal in class BaseJsonNode
      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.
      Overrides:
      asDecimal in class BaseJsonNode
      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.
      Overrides:
      asDecimalOpt in class BaseJsonNode
      Returns:
      Java BigDecimal value this node represents, as Optional<BigDecimal>, if possible to accurately represent; Optional.empty() otherwise
    • _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(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
    • 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