- All Implemented Interfaces:
Serializable
,Iterable<JsonNode>
,tools.jackson.core.TreeNode
,JacksonSerializable
- Direct Known Subclasses:
BigIntegerNode
,DecimalNode
,DoubleNode
,FloatNode
,IntNode
,LongNode
,ShortNode
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class tools.jackson.databind.JsonNode
JsonNode.OverwriteMode
Nested classes/interfaces inherited from interface tools.jackson.databind.JacksonSerializable
JacksonSerializable.Base
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final String
Method for implementation classes to return a short description of contained value, to be used in error messages.final double
asDouble()
Method that will try to convert value of this node to a Java double.final double
asDouble
(double defaultValue) Method that will try to convert value of this node to a Java double.final int
asInt()
Method that will try to convert value of this node to a Java int.final int
asInt
(int defaultValue) Method that will try to convert value of this node to a Java int.final long
asLong()
Method that will try to convert value of this node to a Java long.final long
asLong
(long defaultValue) Method that will try to convert value of this node to a Java long.abstract String
asString()
Method that will return a valid String representation of the contained value, if the node is a value node (methodJsonNode.isValueNode()
returns true), otherwise empty String.abstract BigInteger
Method that will try to access value of this node as aBigInteger
, but if node value cannot be expressed exactly as aBigInteger
, aJsonNodeException
will be thrown.abstract boolean
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).abstract boolean
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).abstract BigDecimal
Method that will try to access value of this node as a JavaBigDecimal
: but if node value cannot be expressed exactly as aBigDecimal
, aJsonNodeException
will be thrown.abstract BigDecimal
decimalValue
(BigDecimal defaultValue) Method similar toJsonNode.decimalValue()
, but that will returndefaultValue
if this node cannot be coerced to JavaBigDecimal
.abstract Optional<BigDecimal>
Method similar toJsonNode.decimalValue()
, but that will return emptyOptional
(Optional.empty()
) if this node cannot be coerced toBigDecimal
.deepCopy()
All current value nodes are immutable, so we can just return them as is.abstract double
Method that will try to access value of this node as a Javadouble
: but if node value cannot be expressed exactly as adouble
, aJsonNodeException
will be thrown.abstract double
doubleValue
(double defaultValue) Method similar toJsonNode.doubleValue()
, but that will return specifieddefaultValue
if this node cannot be converted to Javadouble
.abstract OptionalDouble
Method similar toJsonNode.doubleValue()
, but that will return emptyOptionalLong
(OptionalDouble.empty()
) if this node cannot be converted to Javadouble
.abstract float
Method that will try to access value of this node as a Javafloat
: but if node value cannot be expressed exactly as afloat
, aJsonNodeException
will be thrown.final JsonNodeType
Return the type of this nodeabstract int
intValue()
Method that will try to access value of this node as a Javaint
: but if node value cannot be expressed exactly as anint
, aJsonNodeException
will be thrown.abstract int
intValue
(int defaultValue) Method similar toJsonNode.intValue()
, but that will return specifieddefaultValue
if this node cannot be converted to Javaint
.abstract OptionalInt
Method similar toJsonNode.intValue()
, but that will return emptyOptionalInt
(OptionalInt.empty()
) if this node cannot be converted to Javaint
.abstract boolean
isNaN()
Convenience method for checking whether this node is aFloatNode
orDoubleNode
that contains "not-a-number" (NaN) value.abstract long
Method that will try to access value of this node as a Javalong
: but if node value cannot be expressed exactly as along
, aJsonNodeException
will be thrown.abstract long
longValue
(long defaultValue) Method similar toJsonNode.longValue()
, but that will return specifieddefaultValue
if this node cannot be converted to Javalong
.abstract OptionalLong
Method similar toJsonNode.longValue()
, but that will return emptyOptionalLong
(OptionalLong.empty()
) if this node cannot be converted to Javalong
.abstract tools.jackson.core.JsonParser.NumberType
Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.abstract Number
Method that will try to access value of this node asNumber
that accurately represents its value, if (and only if) this is a number node (returnstrue
forJsonNode.isNumber()
).abstract short
Method that will try to access value of this node as 16-bit signed integer value (Javashort
): but if node value cannot be expressed exactly as ashort
, aJsonNodeException
will be thrown.Methods inherited from class tools.jackson.databind.node.ValueNode
_at, asToken, findParent, findParents, findValue, findValues, findValuesAsString, get, get, has, has, hasNonNull, hasNonNull, isEmpty, path, path, serializeWithType
Methods inherited from class tools.jackson.databind.node.BaseJsonNode
_jsonPointerIfValid, _reportBigIntegerCoercionFractionFail, _reportCoercionFail, _reportDoubleCoercionRangeFail, _reportFloatCoercionRangeFail, _reportIntCoercionFractionFail, _reportIntCoercionRangeFail, _reportLongCoercionFractionFail, _reportLongCoercionRangeFail, _reportShortCoercionFractionFail, _reportShortCoercionRangeFail, _reportWrongNodeType, _withArray, _withObject, _withXxxMayReplace, _withXxxVerifyReplace, asBoolean, asBoolean, asDecimal, asDecimal, asString, binaryValue, booleanValue, booleanValue, booleanValueOpt, findPath, hashCode, isEmbeddedValue, isMissingNode, required, required, serialize, stringValue, stringValue, stringValueOpt, toPrettyString, toString, traverse, withArray, withObject
Methods inherited from class tools.jackson.databind.JsonNode
_reportRequiredViolation, _reportUnsupportedOperation, _this, asOptional, asText, asText, at, at, canConvertToExactIntegral, equals, equals, findParents, findValues, findValuesAsString, forEachEntry, isArray, isBigDecimal, isBigInteger, isBinary, isBoolean, isContainer, isDouble, isFloat, isFloatingPointNumber, isInt, isIntegralNumber, isLong, isNull, isNumber, isObject, isPojo, isShort, isString, isTextual, isValueNode, iterator, optional, optional, properties, propertyNames, propertyStream, require, requiredAt, requiredAt, requireNonNull, size, spliterator, textValue, values, valueStream, withArray, withArray, withArray, withArrayProperty, withObject, withObject, withObject, withObjectProperty
Methods inherited from class tools.jackson.databind.JacksonSerializable.Base
isEmpty
-
Constructor Details
-
NumericNode
protected NumericNode()
-
-
Method Details
-
getNodeType
Description copied from class:JsonNode
Return the type of this node- Specified by:
getNodeType
in classJsonNode
- Returns:
- the node type as a
JsonNodeType
enum value
-
deepCopy
Description copied from class:ValueNode
All current value nodes are immutable, so we can just return them as is. -
_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 classBaseJsonNode
-
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 interfacetools.jackson.core.TreeNode
- Overrides:
numberType
in classBaseJsonNode
-
numberValue
Description copied from class:JsonNode
Method that will try to access value of this node asNumber
that accurately represents its value, if (and only if) this is a number node (returnstrue
forJsonNode.isNumber()
). If this node is NOT a number node, aJsonNodeException
will be thrown.- Overrides:
numberValue
in classBaseJsonNode
- 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 (Javashort
): but if node value cannot be expressed exactly as ashort
, aJsonNodeException
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 classBaseJsonNode
- Returns:
Short
value this node represents, if possible to accurately represent
- JSON Integer values that fit in Java 16-bit signed
-
intValue
public abstract int intValue()Description copied from class:JsonNode
Method that will try to access value of this node as a Javaint
: but if node value cannot be expressed exactly as anint
, aJsonNodeException
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 classBaseJsonNode
- Returns:
Int
value this node represents, if possible to accurately represent
- JSON Integer values that fit in Java 32-bit signed
-
intValue
public abstract int intValue(int defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.intValue()
, but that will return specifieddefaultValue
if this node cannot be converted to Javaint
.- Overrides:
intValue
in classBaseJsonNode
- Parameters:
defaultValue
- Value to return if this node cannot be converted to Javaint
- Returns:
- Java
int
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
intValueOpt
Description copied from class:JsonNode
Method similar toJsonNode.intValue()
, but that will return emptyOptionalInt
(OptionalInt.empty()
) if this node cannot be converted to Javaint
.- Overrides:
intValueOpt
in classBaseJsonNode
- Returns:
- Java
int
value this node represents, asOptionalInt
, 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 Javalong
: but if node value cannot be expressed exactly as along
, aJsonNodeException
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 classBaseJsonNode
- Returns:
Long
value this node represents, if possible to accurately represent
- JSON Integer values that fit in Java 64-bit signed
-
longValue
public abstract long longValue(long defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.longValue()
, but that will return specifieddefaultValue
if this node cannot be converted to Javalong
.- Overrides:
longValue
in classBaseJsonNode
- Parameters:
defaultValue
- Value to return if this node cannot be converted to Javalong
- Returns:
- Java
long
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
longValueOpt
Description copied from class:JsonNode
Method similar toJsonNode.longValue()
, but that will return emptyOptionalLong
(OptionalLong.empty()
) if this node cannot be converted to Javalong
.- Overrides:
longValueOpt
in classBaseJsonNode
- Returns:
- Java
long
value this node represents, asOptionalLong
, if possible to accurately represent;OptionalLong.empty()
otherwise
-
bigIntegerValue
Description copied from class:JsonNode
Method that will try to access value of this node as aBigInteger
, but if node value cannot be expressed exactly as aBigInteger
, aJsonNodeException
will be thrown. Access works for following cases:- JSON Integer values
- JSON Floating-point values that do not have fractional part.
- Overrides:
bigIntegerValue
in classBaseJsonNode
- 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 Javafloat
: but if node value cannot be expressed exactly as afloat
, aJsonNodeException
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 classBaseJsonNode
- Returns:
Float
value this node represents, if possible to accurately represent
- JSON Floating-point values that fit in Java 32-bit
-
doubleValue
public abstract double doubleValue()Description copied from class:JsonNode
Method that will try to access value of this node as a Javadouble
: but if node value cannot be expressed exactly as adouble
, aJsonNodeException
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 classBaseJsonNode
- Returns:
Double
value this node represents, if possible to accurately represent
- JSON Floating-point values that fit in Java 64-bit
-
doubleValue
public abstract double doubleValue(double defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.doubleValue()
, but that will return specifieddefaultValue
if this node cannot be converted to Javadouble
.- Overrides:
doubleValue
in classBaseJsonNode
- Parameters:
defaultValue
- Value to return if this node cannot be converted to Javadouble
- Returns:
- Java
double
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
doubleValueOpt
Description copied from class:JsonNode
Method similar toJsonNode.doubleValue()
, but that will return emptyOptionalLong
(OptionalDouble.empty()
) if this node cannot be converted to Javadouble
.- Overrides:
doubleValueOpt
in classBaseJsonNode
- Returns:
- Java
double
value this node represents, asOptionalDouble
, if possible to accurately represent;OptionalDouble.empty()
otherwise
-
decimalValue
Description copied from class:JsonNode
Method that will try to access value of this node as a JavaBigDecimal
: but if node value cannot be expressed exactly as aBigDecimal
, aJsonNodeException
will be thrown. Access works for following cases:- All JSON Number values
NOTE: for more lenient conversions, use
JsonNode.asDecimal()
- Overrides:
decimalValue
in classBaseJsonNode
- Returns:
BigDecimal
value this node represents, if possible to accurately represent
-
decimalValue
Description copied from class:JsonNode
Method similar toJsonNode.decimalValue()
, but that will returndefaultValue
if this node cannot be coerced to JavaBigDecimal
.- Overrides:
decimalValue
in classBaseJsonNode
- Returns:
BigDecimal
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
decimalValueOpt
Description copied from class:JsonNode
Method similar toJsonNode.decimalValue()
, but that will return emptyOptional
(Optional.empty()
) if this node cannot be coerced toBigDecimal
.- Overrides:
decimalValueOpt
in classBaseJsonNode
- Returns:
- Java
BigDecimal
value this node represents, asOptional<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 classJsonNode
-
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 classJsonNode
-
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 (methodJsonNode.isValueNode()
returns true), otherwise empty String.NOTE: this is NOT same as
JsonNode.toString()
in that result isNOT VALID ENCODED JSON
for all nodes (but is for some, likeNumberNode
s andBooleanNode
s). -
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 classBaseJsonNode
-
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 classBaseJsonNode
-
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 classBaseJsonNode
-
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 classBaseJsonNode
-
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 classBaseJsonNode
-
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 classBaseJsonNode
-
isNaN
public abstract boolean isNaN()Convenience method for checking whether this node is aFloatNode
orDoubleNode
that contains "not-a-number" (NaN) value.- Since:
- 2.9
-