Class NumericNode

All Implemented Interfaces:
Iterable<JsonNode>, JsonSerializable, JsonSerializableWithType
Direct Known Subclasses:
BigIntegerNode, DecimalNode, DoubleNode, IntNode, LongNode

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

    • NumericNode

      protected NumericNode()
  • Method Details

    • isNumber

      public final boolean isNumber()
      Overrides:
      isNumber in class JsonNode
      Returns:
      True if this node represents a numeric Json value
    • getNumberType

      public abstract JsonParser.NumberType getNumberType()
      Description copied from class: JsonNode
      If this node is a numeric type (as per JsonNode.isNumber()), returns native type that node uses to store the numeric value.
      Overrides:
      getNumberType in class BaseJsonNode
    • getNumberValue

      public abstract Number getNumberValue()
      Description copied from class: JsonNode
      Returns numeric value for this node, if and only if this node is numeric (JsonNode.isNumber() returns true); otherwise returns null
      Overrides:
      getNumberValue in class JsonNode
      Returns:
      Number value this node contains, if any (null for non-number nodes).
    • getIntValue

      public abstract int getIntValue()
      Description copied from class: JsonNode
      Returns integer value for this node, if and only if this node is numeric (JsonNode.isNumber() returns true). For other types returns 0. For floating-point numbers, value is truncated using default Java coercion, similar to how cast from double to int operates.
      Overrides:
      getIntValue in class JsonNode
      Returns:
      Integer value this node contains, if any; 0 for non-number nodes.
    • getLongValue

      public abstract long getLongValue()
      Overrides:
      getLongValue in class JsonNode
    • getDoubleValue

      public abstract double getDoubleValue()
      Overrides:
      getDoubleValue in class JsonNode
    • getDecimalValue

      public abstract BigDecimal getDecimalValue()
      Overrides:
      getDecimalValue in class JsonNode
    • getBigIntegerValue

      public abstract BigInteger getBigIntegerValue()
      Overrides:
      getBigIntegerValue in class JsonNode
    • asText

      public abstract String asText()
      Description copied from class: JsonNode
      Method that will return valid String representation of the container value, if the node is a value node (method JsonNode.isValueNode() returns true), otherwise empty String.
      Specified by:
      asText in class JsonNode
    • asInt

      public 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 can not 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 JsonNode
    • asInt

      public 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 can not 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 JsonNode
    • asLong

      public 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 can not be converted to an long (including structured types like Objects and Arrays), default value of 0 will be returned; no exceptions are thrown.

      Overrides:
      asLong in class JsonNode
    • asLong

      public 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 can not be converted to an long (including structured types like Objects and Arrays), specified defaultValue will be returned; no exceptions are thrown.

      Overrides:
      asLong in class JsonNode
    • asDouble

      public 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 can not 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 JsonNode
    • asDouble

      public 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 can not 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 JsonNode