Class NumericNode

All Implemented Interfaces:
Serializable, Iterable<JsonNode>, tools.jackson.core.TreeNode, JacksonSerializable
Direct Known Subclasses:
BigIntegerNode, DecimalNode, DoubleNode, FloatNode, IntNode, LongNode, ShortNode

public abstract class NumericNode extends ValueNode
Intermediate value node used for numeric nodes.
See Also:
  • Constructor Details

    • NumericNode

      protected NumericNode()
  • Method Details

    • getNodeType

      public final 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
    • deepCopy

      public NumericNode 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.
    • _valueDesc

      protected final 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
    • numberType

      public abstract tools.jackson.core.JsonParser.NumberType numberType()
      Description copied from class: BaseJsonNode
      Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.
      Specified by:
      numberType in interface tools.jackson.core.TreeNode
      Overrides:
      numberType in class BaseJsonNode
    • numberValue

      public abstract 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.
      Overrides:
      numberValue in class BaseJsonNode
      Returns:
      Number value this node contains, if numeric node
    • shortValue

      public abstract 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.

      Overrides:
      shortValue in class BaseJsonNode
      Returns:
      Short value this node represents, if possible to accurately represent
    • intValue

      public abstract 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()

      Overrides:
      intValue in class BaseJsonNode
      Returns:
      Int value this node represents, if possible to accurately represent
    • intValue

      public abstract 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.
      Overrides:
      intValue in class BaseJsonNode
      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 abstract 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.
      Overrides:
      intValueOpt in class BaseJsonNode
      Returns:
      Java int value this node represents, as OptionalInt, if possible to accurately represent; OptionalInt.empty() otherwise
    • longValue

      public abstract 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()

      Overrides:
      longValue in class BaseJsonNode
      Returns:
      Long value this node represents, if possible to accurately represent
    • longValue

      public abstract 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 Java long.
      Overrides:
      longValue in class BaseJsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to Java long
      Returns:
      Java long value this node represents, if possible to accurately represent; defaultValue otherwise
    • longValueOpt

      public abstract 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.
      Overrides:
      longValueOpt in class BaseJsonNode
      Returns:
      Java long value this node represents, as OptionalLong, if possible to accurately represent; OptionalLong.empty() otherwise
    • bigIntegerValue

      public abstract 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.

      Overrides:
      bigIntegerValue in class BaseJsonNode
      Returns:
      BigInteger value this node represents, if possible to accurately represent
    • floatValue

      public abstract 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

      Overrides:
      floatValue in class BaseJsonNode
      Returns:
      Float value this node represents, if possible to accurately represent
    • doubleValue

      public abstract double doubleValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java 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()

      Overrides:
      doubleValue in class BaseJsonNode
      Returns:
      Double value this node represents, if possible to accurately represent
    • doubleValue

      public abstract 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 Java double.
      Overrides:
      doubleValue in class BaseJsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to Java double
      Returns:
      Java double value this node represents, if possible to accurately represent; defaultValue otherwise
    • doubleValueOpt

      public abstract 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.
      Overrides:
      doubleValueOpt in class BaseJsonNode
      Returns:
      Java double value this node represents, as OptionalDouble, if possible to accurately represent; OptionalDouble.empty() otherwise
    • decimalValue

      public abstract 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()

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

      public abstract 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.
      Overrides:
      decimalValue in class BaseJsonNode
      Returns:
      BigDecimal value this node represents, if possible to accurately represent; defaultValue otherwise
    • decimalValueOpt

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

      public abstract boolean canConvertToInt()
      Description copied from class: JsonNode
      Method that can be used to check whether this node is a numeric node (JsonNode.isNumber() would return true) AND can be converted without loss to it (that is, its value fits within Java's 32-bit signed integer type, int and if it is a floating-point number, it does not have fractional part).

      NOTE: this method does not consider possible value type conversion from non-number types like JSON String into Number; so even if this method returns false, it is possible that JsonNode.asInt() could still succeed.

      Overrides:
      canConvertToInt in class JsonNode
    • canConvertToLong

      public abstract boolean canConvertToLong()
      Description copied from class: JsonNode
      Method that can be used to check whether this node is a numeric node (JsonNode.isNumber() would return true) AND can be converted without loss to it (that is, its value fits within Java's 64-bit signed integer type, long and if it is a floating-point number, it does not have fractional part).

      NOTE: this method does not consider possible value type conversion from non-number types like JSON String into Number; so even if this method returns false, it is possible that JsonNode.asLong() could still succeed.

      Overrides:
      canConvertToLong in class JsonNode
    • asString

      public abstract String asString()
      Description copied from class: JsonNode
      Method that will return a valid String representation of the contained value, if the node is a value node (method JsonNode.isValueNode() returns true), otherwise empty String.

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

      NOT VALID ENCODED JSON

      for all nodes (but is for some, like NumberNodes and BooleanNodes).
      Specified by:
      asString in class JsonNode
    • asInt

      public final int asInt()
      Description copied from class: JsonNode
      Method that will try to convert value of this node to a Java int. Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules.

      If representation cannot be converted to an int (including structured types like Objects and Arrays), default value of 0 will be returned; no exceptions are thrown.

      Overrides:
      asInt in class BaseJsonNode
    • asInt

      public final int asInt(int defaultValue)
      Description copied from class: JsonNode
      Method that will try to convert value of this node to a Java int. Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules.

      If representation cannot be converted to an int (including structured types like Objects and Arrays), specified defaultValue will be returned; no exceptions are thrown.

      Overrides:
      asInt in class BaseJsonNode
    • asLong

      public final long asLong()
      Description copied from class: JsonNode
      Method that will try to convert value of this node to a Java long. Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules.

      If representation cannot be converted to a long (including structured types like Objects and Arrays), default value of 0 will be returned; no exceptions are thrown.

      Overrides:
      asLong in class BaseJsonNode
    • asLong

      public final long asLong(long defaultValue)
      Description copied from class: JsonNode
      Method that will try to convert value of this node to a Java long. Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules.

      If representation cannot be converted to a long (including structured types like Objects and Arrays), specified defaultValue will be returned; no exceptions are thrown.

      Overrides:
      asLong in class BaseJsonNode
    • asDouble

      public final double asDouble()
      Description copied from class: JsonNode
      Method that will try to convert value of this node to a Java double. Numbers are coerced using default Java rules; booleans convert to 0.0 (false) and 1.0 (true), and Strings are parsed using default Java language integer parsing rules.

      If representation cannot be converted to an int (including structured types like Objects and Arrays), default value of 0.0 will be returned; no exceptions are thrown.

      Overrides:
      asDouble in class BaseJsonNode
    • asDouble

      public final double asDouble(double defaultValue)
      Description copied from class: JsonNode
      Method that will try to convert value of this node to a Java double. Numbers are coerced using default Java rules; booleans convert to 0.0 (false) and 1.0 (true), and Strings are parsed using default Java language integer parsing rules.

      If representation cannot be converted to an int (including structured types like Objects and Arrays), specified defaultValue will be returned; no exceptions are thrown.

      Overrides:
      asDouble in class BaseJsonNode
    • isNaN

      public abstract boolean isNaN()
      Convenience method for checking whether this node is a FloatNode or DoubleNode that contains "not-a-number" (NaN) value.
      Since:
      2.9