Class NumericNode
- java.lang.Object
-
- com.fasterxml.jackson.databind.JsonSerializable.Base
-
- com.fasterxml.jackson.databind.JsonNode
-
- com.fasterxml.jackson.databind.node.BaseJsonNode
-
- com.fasterxml.jackson.databind.node.ValueNode
-
- com.fasterxml.jackson.databind.node.NumericNode
-
- All Implemented Interfaces:
TreeNode,JsonSerializable,java.io.Serializable,java.lang.Iterable<JsonNode>
- 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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonNode
JsonNode.OverwriteMode
-
Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.JsonSerializable
JsonSerializable.Base
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description doubleasDouble()Method that will try to convert value of this node to a Java double.doubleasDouble(double defaultValue)Method that will try to convert value of this node to a Java double.intasInt()Method that will try to convert value of this node to a Java int.intasInt(int defaultValue)Method that will try to convert value of this node to a Java int.longasLong()Method that will try to convert value of this node to a Java long.longasLong(long defaultValue)Method that will try to convert value of this node to a Java long.abstract java.lang.StringasText()Method that will return a valid String representation of the container value, if the node is a value node (methodJsonNode.isValueNode()returns true), otherwise empty String.abstract java.math.BigIntegerbigIntegerValue()Returns integer value for this node (asBigInteger), if and only if this node is numeric (JsonNode.isNumber()returns true).abstract booleancanConvertToInt()Method that can be used to check whether this node is a numeric node (JsonNode.isNumber()would return true) AND its value fits within Java's 32-bit signed integer type,int.abstract booleancanConvertToLong()Method that can be used to check whether this node is a numeric node (JsonNode.isNumber()would return true) AND its value fits within Java's 64-bit signed integer type,long.abstract java.math.BigDecimaldecimalValue()Returns floating point value for this node (asBigDecimal), if and only if this node is numeric (JsonNode.isNumber()returns true).abstract doubledoubleValue()Returns 64-bit floating point (double) value for this node, if and only if this node is numeric (JsonNode.isNumber()returns true).JsonNodeTypegetNodeType()Return the type of this nodeabstract intintValue()Returns integer value for this node, if and only if this node is numeric (JsonNode.isNumber()returns true).booleanisNaN()Convenience method for checking whether this node is aFloatNodeorDoubleNodethat contains "not-a-number" (NaN) value.abstract longlongValue()Returns 64-bit long value for this node, if and only if this node is numeric (JsonNode.isNumber()returns true).abstract JsonParser.NumberTypenumberType()Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.abstract java.lang.NumbernumberValue()Returns numeric value for this node, if and only if this node is numeric (JsonNode.isNumber()returns true); otherwise returns null-
Methods inherited from class com.fasterxml.jackson.databind.node.ValueNode
asToken, deepCopy, findParent, findParents, findValue, findValues, findValuesAsText, get, get, has, has, hasNonNull, hasNonNull, isEmpty, path, path, serializeWithType
-
Methods inherited from class com.fasterxml.jackson.databind.node.BaseJsonNode
findPath, hashCode, required, required, serialize, toPrettyString, toString, traverse, traverse, withArray, withObject
-
Methods inherited from class com.fasterxml.jackson.databind.JsonNode
asBoolean, asBoolean, asText, at, at, binaryValue, booleanValue, canConvertToExactIntegral, elements, equals, equals, fieldNames, fields, findParents, findValues, findValuesAsText, floatValue, isArray, isBigDecimal, isBigInteger, isBinary, isBoolean, isContainerNode, isDouble, isFloat, isFloatingPointNumber, isInt, isIntegralNumber, isLong, isMissingNode, isNull, isNumber, isObject, isPojo, isShort, isTextual, isValueNode, iterator, properties, require, requiredAt, requiredAt, requireNonNull, shortValue, size, textValue, with, withArray, withArray, withArray, withArrayProperty, withObject, withObject, withObject, withObjectProperty
-
Methods inherited from class com.fasterxml.jackson.databind.JsonSerializable.Base
isEmpty
-
-
-
-
Method Detail
-
getNodeType
public final JsonNodeType getNodeType()
Description copied from class:JsonNodeReturn the type of this node- Specified by:
getNodeTypein classJsonNode- Returns:
- the node type as a
JsonNodeTypeenum value
-
numberType
public abstract JsonParser.NumberType numberType()
Description copied from class:BaseJsonNodeReturns code that identifies type of underlying numeric value, if (and only if) node is a number node.- Specified by:
numberTypein interfaceTreeNode- Overrides:
numberTypein classBaseJsonNode- Returns:
- Type of number contained, if any; or null if node does not contain numeric value.
-
numberValue
public abstract java.lang.Number numberValue()
Description copied from class:JsonNodeReturns numeric value for this node, if and only if this node is numeric (JsonNode.isNumber()returns true); otherwise returns null- Overrides:
numberValuein classJsonNode- Returns:
- Number value this node contains, if any (null for non-number nodes).
-
intValue
public abstract int intValue()
Description copied from class:JsonNodeReturns 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.
-
longValue
public abstract long longValue()
Description copied from class:JsonNodeReturns 64-bit long 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 long operates.
-
doubleValue
public abstract double doubleValue()
Description copied from class:JsonNodeReturns 64-bit floating point (double) value for this node, if and only if this node is numeric (JsonNode.isNumber()returns true). For other types returns 0.0. For integer values, conversion is done using coercion; this may result in overflows withBigIntegervalues.- Overrides:
doubleValuein classJsonNode- Returns:
- 64-bit double value this node contains, if any; 0.0 for non-number nodes.
-
decimalValue
public abstract java.math.BigDecimal decimalValue()
Description copied from class:JsonNodeReturns floating point value for this node (asBigDecimal), if and only if this node is numeric (JsonNode.isNumber()returns true). For other types returnsBigDecimal.ZERO.- Overrides:
decimalValuein classJsonNode- Returns:
BigDecimalvalue this node contains, if numeric node;BigDecimal.ZEROfor non-number nodes.
-
bigIntegerValue
public abstract java.math.BigInteger bigIntegerValue()
Description copied from class:JsonNodeReturns integer value for this node (asBigInteger), if and only if this node is numeric (JsonNode.isNumber()returns true). For other types returnsBigInteger.ZERO.NOTE: In Jackson 2.x MAY throw
StreamConstraintsExceptionif the scale of the underlyingBigDecimalis too large to convert (NOTE: thrown "sneakily" in Jackson 2.x due to API compatibility restrictions)- Overrides:
bigIntegerValuein classJsonNode- Returns:
BigIntegervalue this node contains, if numeric node;BigInteger.ZEROfor non-number nodes.
-
canConvertToInt
public abstract boolean canConvertToInt()
Description copied from class:JsonNodeMethod that can be used to check whether this node is a numeric node (JsonNode.isNumber()would return true) AND its value fits within Java's 32-bit signed integer type,int. Note that floating-point numbers are convertible if the integral part fits without overflow (as per standard Java coercion rules)NOTE: this method does not consider possible value type conversion from JSON String into Number; so even if this method returns false, it is possible that
JsonNode.asInt()could still succeed if node is a JSON String representing integral number, or boolean.- Overrides:
canConvertToIntin classJsonNode
-
canConvertToLong
public abstract boolean canConvertToLong()
Description copied from class:JsonNodeMethod that can be used to check whether this node is a numeric node (JsonNode.isNumber()would return true) AND its value fits within Java's 64-bit signed integer type,long. Note that floating-point numbers are convertible if the integral part fits without overflow (as per standard Java coercion rules)NOTE: this method does not consider possible value type conversion from JSON String into Number; so even if this method returns false, it is possible that
JsonNode.asLong()could still succeed if node is a JSON String representing integral number, or boolean.- Overrides:
canConvertToLongin classJsonNode
-
asText
public abstract java.lang.String asText()
Description copied from class:JsonNodeMethod that will return a valid String representation of the container value, if the node is a value node (methodJsonNode.isValueNode()returns true), otherwise empty String.
-
asInt
public final int asInt()
Description copied from class:JsonNodeMethod 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.
-
asInt
public final int asInt(int defaultValue)
Description copied from class:JsonNodeMethod 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.
-
asLong
public final long asLong()
Description copied from class:JsonNodeMethod 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.
-
asLong
public final long asLong(long defaultValue)
Description copied from class:JsonNodeMethod 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.
-
asDouble
public final double asDouble()
Description copied from class:JsonNodeMethod 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.
-
asDouble
public final double asDouble(double defaultValue)
Description copied from class:JsonNodeMethod 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.
-
isNaN
public boolean isNaN()
Convenience method for checking whether this node is aFloatNodeorDoubleNodethat contains "not-a-number" (NaN) value.- Since:
- 2.9
-
-