- All Implemented Interfaces:
Serializable
,Iterable<JsonNode>
,TreeNode
,JacksonSerializable
- Direct Known Subclasses:
ContainerNode
,MissingNode
,ValueNode
JsonNode
implementations.
The main addition here is that we declare that sub-classes must
implement JacksonSerializable
.
This simplifies object mapping aspects a bit, as no external serializers are needed.
Note that support for Serializable
is added here and so all subtypes
are fully JDK serializable: but also note that serialization is as JSON and should
only be used for interoperability purposes where other approaches are not available.
- 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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Boolean
Method sub-classes should override if they can produceboolean
values viaasBoolean()
-- if not, returnnull
(in which case appropriate error will be thrown or default value returned).protected String
Method sub-classes should override if they can produceString
values viaasString()
-- if not, returnnull
(in which case appropriate error will be thrown or default value returned).protected JsonPointer
_jsonPointerIfValid
(String exprOrProperty) protected BigDecimal
protected BigInteger
protected BigInteger
protected <T> T
_reportCoercionFail
(String method, Class<?> targetType, String message) protected double
_reportDoubleCoercionRangeFail
(String method) protected float
_reportFloatCoercionRangeFail
(String method) protected int
_reportIntCoercionFractionFail
(String method) protected int
_reportIntCoercionNaNFail
(String method) protected int
_reportIntCoercionRangeFail
(String method) protected long
protected long
_reportLongCoercionNaNFail
(String method) protected long
_reportLongCoercionRangeFail
(String method) protected short
protected short
_reportShortCoercionRangeFail
(String method) protected <T> T
_reportWrongNodeType
(String msgTemplate, Object... args) Helper method that throwsJsonNodeException
as a result of this node being of wrong typeprotected abstract String
Method for implementation classes to return a short description of contained value, to be used in error messages.protected ArrayNode
_withArray
(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) protected ObjectNode
_withObject
(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) protected boolean
_withXxxMayReplace
(JsonNode node, JsonNode.OverwriteMode overwriteMode) protected void
_withXxxVerifyReplace
(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex, JsonNode toReplace) Method similar toJsonNode.bigIntegerValue()
but in addition to coercing Number values (same asJsonNode.bigIntegerValue()
), will also try to coerce a couple of additional types (or cases): JSON Floating-point numbers with fractions (ones without fractions are ok forJsonNode.bigIntegerValue()
) will be truncated to integer value (like withBigDecimal.toBigInteger()
)) JSON Strings that represent JSON Numbers ("stringified" numbers) JSON Null (converted to0
)) POJO nodes that contain Number valuesasBigInteger
(BigInteger defaultValue) Method similar toJsonNode.asBigInteger()
, but that will return specifieddefaultValue
if this node cannot be converted toBigInteger
.Method similar toJsonNode.bigIntegerValue()
, but that will return empty (Optional.empty()
) if this node cannot be converted to JavaBigInteger
.boolean
Method that will try to convert value of this node to a Javaboolean
.boolean
asBoolean
(boolean defaultValue) Similar toJsonNode.asBoolean()
, but instead of throwing an exception for non-coercible values, will return specified default value.Similar toJsonNode.asBoolean()
, but instead of throwing an exception for non-coercible values, will returnOptional.empty()
.Method that will try to access value of this node as aBigDecimal
: but if node value cannot be expressed exactly as aBigDecimal
, aJsonNodeException
will be thrown.asDecimal
(BigDecimal defaultValue) Method similar toJsonNode.asDecimal()
, but that will returndefaultValue
if this node cannot be coerced to JavaBigDecimal
.Method similar toJsonNode.asDecimal()
, but that will return emptyOptional
(Optional.empty()
) if this node cannot be coerced toBigDecimal
.double
asDouble()
Method similar toJsonNode.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 to0.0d
) POJO nodes that contain Number valuesdouble
asDouble
(double defaultValue) Method similar toJsonNode.asDouble()
, but that will returndefaultValue
if this node cannot be coerced todouble
.Method similar toJsonNode.asDouble()
, but that will return (OptionalDouble.empty()
) if this node cannot be coerced todouble
.int
asInt()
Method similar toJsonNode.intValue()
but in addition to coercing Number values (same asJsonNode.intValue()
), will also try to coerce a couple of additional types (or cases): JSON Floating-point numbers with fractions (ones without fractions are ok forJsonNode.intValue()
) will be truncated toint
(if (and only if) they fit inint
range).int
asInt
(int defaultValue) Method similar toJsonNode.intValue()
, but that will return specifieddefaultValue
if this node cannot be converted toint
.asIntOpt()
Method similar toJsonNode.asInt()
, but that will return (OptionalInt.empty()
) if this node cannot be coerced toint
.long
asLong()
Method similar toJsonNode.longValue()
but in addition to coercing Number values (same asJsonNode.longValue()
), will also try to coerce a couple of additional types (or cases): JSON Floating-point numbers with fractions (ones without fractions are ok forJsonNode.longValue()
) will be truncated tolong
(if (and only if) they fit inlong
range).long
asLong
(long defaultValue) Method similar toJsonNode.asLong()
, but that will return specifieddefaultValue
if this node cannot be coerced tolong
(instead of throwing an exception).Method similar toJsonNode.asLong()
, but that will return (OptionalLong.empty()
) if this node cannot be coerced tolong
.asString()
Method that will try to convert value of this node to aString
.Similar toJsonNode.asString()
, but instead of throwing an exception for non-coercible values, will return specified default value.Similar toJsonNode.asString()
, but instead of throwing an exception for non-coercible values, will returnOptional.empty()
.abstract JsonToken
asToken()
Method that can be used for efficient type detection when using stream abstraction for traversing nodes.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.bigIntegerValue
(BigInteger defaultValue) Method similar toJsonNode.bigIntegerValue()
, but that will return specifieddefaultValue
if this node cannot be converted to JavaBigInteger
.Method similar toJsonNode.bigIntegerValue()
, but that will return empty (Optional.empty()
) if this node cannot be converted to JavaBigInteger
.byte[]
Method that will try to access value of this node as binary value (Javabyte[]
) which works if (and only if) node contains binary value (for JSON, Base64-encoded String, for other formats native binary value): if not, aJsonNodeException
will be thrown.boolean
Method that will try to access value of this node as a Javaboolean
which works if (and only if) node contains JSON boolean value: if not, aJsonNodeException
will be thrown.boolean
booleanValue
(boolean defaultValue) Method similar toJsonNode.booleanValue()
, but that will return specifieddefaultValue
if this node does not contain a JSON boolean.Method similar toJsonNode.booleanValue()
, but that will returnOptional.empty()
if this node does not contain a JSON boolean.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.decimalValue
(BigDecimal defaultValue) Method similar toJsonNode.decimalValue()
, but that will returndefaultValue
if this node cannot be coerced to JavaBigDecimal
.Method similar toJsonNode.decimalValue()
, but that will return emptyOptional
(Optional.empty()
) if this node cannot be coerced toBigDecimal
.double
Method that will try to access value of this node as adouble
: but if node value cannot be expressed exactly as adouble
, aJsonNodeException
will be thrown.double
doubleValue
(double defaultValue) Method similar toJsonNode.doubleValue()
, but that will return specifieddefaultValue
if this node cannot be converted todouble
.Method similar toJsonNode.doubleValue()
, but that will return emptyOptionalLong
(OptionalDouble.empty()
) if this node cannot be converted to Javadouble
.final JsonNode
Method similar toJsonNode.findValue(java.lang.String)
, but that will return a "missing node" instead of null if no field is found.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.abstract int
hashCode()
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.int
intValue
(int defaultValue) Method similar toJsonNode.intValue()
, but that will return specifieddefaultValue
if this node cannot be converted to Javaint
.Method similar toJsonNode.intValue()
, but that will return emptyOptionalInt
(OptionalInt.empty()
) if this node cannot be converted to Javaint
.boolean
boolean
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.long
longValue
(long defaultValue) Method similar toJsonNode.longValue()
, but that will return specifieddefaultValue
if this node cannot be converted tolong
.Method similar toJsonNode.longValue()
, but that will return emptyOptionalLong
(OptionalLong.empty()
) if this node cannot be converted to Javalong
.Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.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()
).required
(int index) Method is functionally equivalent topath(index).required()
and can be used to check that this node is anArrayNode
(that is, represents JSON Array value) and has value for specifiedindex
(but note that value may be explicit JSON null value).Method is functionally equivalent topath(propertyName).required()
and can be used to check that this node is anObjectNode
(that is, represents JSON Object value) and has value for specified property with keypropertyName
(but note that value may be explicit JSON null value).abstract void
serialize
(JsonGenerator jgen, SerializationContext ctxt) Method called to serialize node instances using given generator.abstract void
serializeWithType
(JsonGenerator jgen, SerializationContext ctxt, TypeSerializer typeSer) Type information is needed, even if JsonNode instances are "plain" JSON, since they may be mixed with other types.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.Method that will try to access value of this node as a JavaString
which works if (and only if) node contains JSON String value: if not, aJsonNodeException
will be thrown.stringValue
(String defaultValue) Method similar toJsonNode.stringValue()
, but that will return specifieddefaultValue
if this node does not contain a JSON String.Method similar toJsonNode.stringValue()
, but that will returnOptional.empty()
if this node does not contain a JSON String.Alternative toJsonNode.toString()
that will serialize this node using Jackson default pretty-printer.toString()
Method that will produce (as of Jackson 2.10) valid JSON using default settings of databind, as String.traverse
(ObjectReadContext readCtxt) withArray
(JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) Method that can be called on Object or Array nodes, to access a Array-valued node pointed to by givenJsonPointer
, if such a node exists: or if not, an attempt is made to create one and return it.withObject
(JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) Method that can be called on Object or Array nodes, to access a Object-valued node pointed to by givenJsonPointer
, if such a node exists: or if not, an attempt is made to create one and return it.Methods inherited from class tools.jackson.databind.JsonNode
_at, _reportRequiredViolation, _reportUnsupportedOperation, _this, asOptional, asText, asText, at, at, canConvertToExactIntegral, canConvertToInt, canConvertToLong, deepCopy, equals, equals, findParent, findParents, findParents, findValue, findValues, findValues, findValuesAsString, findValuesAsString, forEachEntry, get, get, getNodeType, has, has, hasNonNull, hasNonNull, isArray, isBigDecimal, isBigInteger, isBinary, isBoolean, isContainer, isDouble, isEmpty, isFloat, isFloatingPointNumber, isInt, isIntegralNumber, isLong, isNull, isNumber, isObject, isPojo, isShort, isString, isTextual, isValueNode, iterator, optional, optional, path, path, 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
-
Field Details
-
OPT_FALSE
-
OPT_TRUE
-
-
Constructor Details
-
BaseJsonNode
protected BaseJsonNode()
-
-
Method Details
-
isMissingNode
public boolean isMissingNode()- Specified by:
isMissingNode
in interfaceTreeNode
- Overrides:
isMissingNode
in classJsonNode
-
isEmbeddedValue
public boolean isEmbeddedValue()- Specified by:
isEmbeddedValue
in interfaceTreeNode
-
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.- Specified by:
numberValue
in classJsonNode
- Returns:
- Number value this node contains, if numeric node
-
shortValue
public 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.
- Specified by:
shortValue
in classJsonNode
- Returns:
Short
value this node represents, if possible to accurately represent
- JSON Integer values that fit in Java 16-bit signed
-
intValue
public 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()
- JSON Integer values that fit in Java 32-bit signed
-
intValue
public 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
. -
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
.- Specified by:
intValueOpt
in classJsonNode
- Returns:
- Java
int
value this node represents, asOptionalInt
, if possible to accurately represent;OptionalInt.empty()
otherwise
-
asInt
public int asInt()Description copied from class:JsonNode
Method similar toJsonNode.intValue()
but in addition to coercing Number values (same asJsonNode.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 toint
(if (and only if) they fit inint
range). - JSON Strings that represent JSON Numbers ("stringified" numbers)
- JSON Null (converted to
0
)) - POJO nodes that contain Number values
- JSON Floating-point numbers with fractions (ones without fractions
are ok for
-
asInt
public int asInt(int defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.intValue()
, but that will return specifieddefaultValue
if this node cannot be converted toint
. -
asIntOpt
Description copied from class:JsonNode
Method similar toJsonNode.asInt()
, but that will return (OptionalInt.empty()
) if this node cannot be coerced toint
.- Specified by:
asIntOpt
in classJsonNode
- Returns:
OptionalInt
value this node represents, if possible to accurately represent;OptionalInt.empty()
otherwise
-
longValue
public 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()
- JSON Integer values that fit in Java 64-bit signed
-
longValue
public long longValue(long defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.longValue()
, but that will return specifieddefaultValue
if this node cannot be converted tolong
. -
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
.- Specified by:
longValueOpt
in classJsonNode
- Returns:
- Java
long
value this node represents, asOptionalLong
, if possible to accurately represent;OptionalLong.empty()
otherwise
-
asLong
public long asLong()Description copied from class:JsonNode
Method similar toJsonNode.longValue()
but in addition to coercing Number values (same asJsonNode.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 tolong
(if (and only if) they fit inlong
range). - JSON Strings that represent JSON Numbers ("stringified" numbers)
- JSON Null (converted to
0
)) - POJO nodes that contain Number values
- JSON Floating-point numbers with fractions (ones without fractions
are ok for
-
asLong
public long asLong(long defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.asLong()
, but that will return specifieddefaultValue
if this node cannot be coerced tolong
(instead of throwing an exception). -
asLongOpt
Description copied from class:JsonNode
Method similar toJsonNode.asLong()
, but that will return (OptionalLong.empty()
) if this node cannot be coerced tolong
.- Specified by:
asLongOpt
in classJsonNode
- Returns:
OptionalLong
value this node represents (or can be coerced to),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.
- Specified by:
bigIntegerValue
in classJsonNode
- Returns:
BigInteger
value this node represents, if possible to accurately represent
-
bigIntegerValue
Description copied from class:JsonNode
Method similar toJsonNode.bigIntegerValue()
, but that will return specifieddefaultValue
if this node cannot be converted to JavaBigInteger
.- Specified by:
bigIntegerValue
in classJsonNode
- Parameters:
defaultValue
- Value to return if this node cannot be converted to JavaBigInteger
- Returns:
- Java
BigInteger
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
bigIntegerValueOpt
Description copied from class:JsonNode
Method similar toJsonNode.bigIntegerValue()
, but that will return empty (Optional.empty()
) if this node cannot be converted to JavaBigInteger
.- Specified by:
bigIntegerValueOpt
in classJsonNode
- Returns:
- Java
BigInteger
value this node represents, asOptional<BigInteger>
, if possible to accurately represent;Optional.empty()
otherwise
-
asBigInteger
Description copied from class:JsonNode
Method similar toJsonNode.bigIntegerValue()
but in addition to coercing Number values (same asJsonNode.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 withBigDecimal.toBigInteger()
)) - JSON Strings that represent JSON Numbers ("stringified" numbers)
- JSON Null (converted to
0
)) - POJO nodes that contain Number values
- Specified by:
asBigInteger
in classJsonNode
- Returns:
BigInteger
value this node represents, if possible to accurately convert;defaultValue
otherwise
- JSON Floating-point numbers with fractions (ones without fractions
are ok for
-
asBigInteger
Description copied from class:JsonNode
Method similar toJsonNode.asBigInteger()
, but that will return specifieddefaultValue
if this node cannot be converted toBigInteger
.- Specified by:
asBigInteger
in classJsonNode
- Parameters:
defaultValue
- Value to return if this node cannot be converted toBigInteger
- Returns:
BigInteger
value this node represents, if possible to accurately convert;defaultValue
otherwise
-
asBigIntegerOpt
Description copied from class:JsonNode
Method similar toJsonNode.bigIntegerValue()
, but that will return empty (Optional.empty()
) if this node cannot be converted to JavaBigInteger
.- Specified by:
asBigIntegerOpt
in classJsonNode
- Returns:
BigInteger
value this node represents, asOptional<BigInteger>
, if possible to accurately represent;Optional.empty()
otherwise.
-
floatValue
public 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
- Specified by:
floatValue
in classJsonNode
- Returns:
Float
value this node represents, if possible to accurately represent
- JSON Floating-point values that fit in Java 32-bit
-
doubleValue
public double doubleValue()Description copied from class:JsonNode
Method that will try to access value of this node as adouble
: 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()
- Specified by:
doubleValue
in classJsonNode
- Returns:
Double
value this node represents, if possible to accurately represent
- JSON Floating-point values that fit in Java 64-bit
-
doubleValue
public double doubleValue(double defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.doubleValue()
, but that will return specifieddefaultValue
if this node cannot be converted todouble
.- Specified by:
doubleValue
in classJsonNode
- Parameters:
defaultValue
- Value to return if this node cannot be converted todouble
- Returns:
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
.- Specified by:
doubleValueOpt
in classJsonNode
- Returns:
- Java
double
value this node represents, asOptionalDouble
, if possible to accurately represent;OptionalDouble.empty()
otherwise
-
asDouble
public double asDouble()Description copied from class:JsonNode
Method similar toJsonNode.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
-
asDouble
public double asDouble(double defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.asDouble()
, but that will returndefaultValue
if this node cannot be coerced todouble
. -
asDoubleOpt
Description copied from class:JsonNode
Method similar toJsonNode.asDouble()
, but that will return (OptionalDouble.empty()
) if this node cannot be coerced todouble
.- Specified by:
asDoubleOpt
in classJsonNode
- Returns:
OptionalDouble
value this node represents, 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()
- Specified by:
decimalValue
in classJsonNode
- 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
.- Specified by:
decimalValue
in classJsonNode
- 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
.- Specified by:
decimalValueOpt
in classJsonNode
- Returns:
- Java
BigDecimal
value this node represents, asOptional<BigDecimal>
, if possible to accurately represent;Optional.empty()
otherwise
-
asDecimal
Description copied from class:JsonNode
Method that will try to access value of this node as aBigDecimal
: but if node value cannot be expressed exactly as aBigDecimal
, aJsonNodeException
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
- Specified by:
asDecimal
in classJsonNode
- Returns:
BigDecimal
value this node represents, if possible to accurately represent
-
asDecimal
Description copied from class:JsonNode
Method similar toJsonNode.asDecimal()
, but that will returndefaultValue
if this node cannot be coerced to JavaBigDecimal
. -
asDecimalOpt
Description copied from class:JsonNode
Method similar toJsonNode.asDecimal()
, but that will return emptyOptional
(Optional.empty()
) if this node cannot be coerced toBigDecimal
.- Specified by:
asDecimalOpt
in classJsonNode
- Returns:
- Java
BigDecimal
value this node represents, asOptional<BigDecimal>
, if possible to accurately represent;Optional.empty()
otherwise
-
binaryValue
public byte[] binaryValue()Description copied from class:JsonNode
Method that will try to access value of this node as binary value (Javabyte[]
) which works if (and only if) node contains binary value (for JSON, Base64-encoded String, for other formats native binary value): if not, aJsonNodeException
will be thrown. To check if this method can be used, you may callJsonNode.isBinary()
.- Specified by:
binaryValue
in classJsonNode
- Returns:
- Binary value this node represents (if node contains binary value)
-
booleanValue
public boolean booleanValue()Description copied from class:JsonNode
Method that will try to access value of this node as a Javaboolean
which works if (and only if) node contains JSON boolean value: if not, aJsonNodeException
will be thrown.NOTE: for more lenient conversions, use
JsonNode.asBoolean()
- Specified by:
booleanValue
in classJsonNode
- Returns:
boolean
value this node represents (if JSON boolean)
-
booleanValue
public boolean booleanValue(boolean defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.booleanValue()
, but that will return specifieddefaultValue
if this node does not contain a JSON boolean.- Specified by:
booleanValue
in classJsonNode
- Parameters:
defaultValue
- Value to return if this node does not contain a JSON boolean.- Returns:
- Java
boolean
value this node represents (if JSON boolean);defaultValue
otherwise
-
booleanValueOpt
Description copied from class:JsonNode
Method similar toJsonNode.booleanValue()
, but that will returnOptional.empty()
if this node does not contain a JSON boolean.- Specified by:
booleanValueOpt
in classJsonNode
- Returns:
Optional<Boolean>
value (if node represents JSON boolean);Optional.empty()
otherwise
-
asBoolean
public boolean asBoolean()Description copied from class:JsonNode
Method that will try to convert value of this node to a Javaboolean
. JSON Booleans map naturally; Integer numbers other than 0 map to true, and 0 maps to false;null
maps to false and Strings 'true' and 'false' map to corresponding values. Other values (including structured types like Objects and Arrays) will result in aJsonNodeException
being thrown. -
asBoolean
public boolean asBoolean(boolean defaultValue) Description copied from class:JsonNode
Similar toJsonNode.asBoolean()
, but instead of throwing an exception for non-coercible values, will return specified default value. -
asBooleanOpt
Description copied from class:JsonNode
Similar toJsonNode.asBoolean()
, but instead of throwing an exception for non-coercible values, will returnOptional.empty()
.- Specified by:
asBooleanOpt
in classJsonNode
-
stringValue
Description copied from class:JsonNode
Method that will try to access value of this node as a JavaString
which works if (and only if) node contains JSON String value: if not, aJsonNodeException
will be thrown.NOTE: for more lenient conversions, use
JsonNode.asString()
NOTE: in Jackson 2.x, was
textValue()
.- Specified by:
stringValue
in classJsonNode
- Returns:
String
value this node represents (if JSON String)
-
stringValue
Description copied from class:JsonNode
Method similar toJsonNode.stringValue()
, but that will return specifieddefaultValue
if this node does not contain a JSON String.- Specified by:
stringValue
in classJsonNode
- 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
-
stringValueOpt
Description copied from class:JsonNode
Method similar toJsonNode.stringValue()
, but that will returnOptional.empty()
if this node does not contain a JSON String.- Specified by:
stringValueOpt
in classJsonNode
- Returns:
Optional<String>
value (if node represents JSON String);Optional.empty()
otherwise
-
asString
Description copied from class:JsonNode
Method that will try to convert value of this node to aString
. JSON Strings map naturally; other scalars map to their string representation (including Binary data as Base64 encoded String); JSONnull
s map to empty String. Other values (including structured types like Objects and Arrays, and "missing" value) will result in aJsonNodeException
being thrown.NOTE: this is NOT same as
JsonNode.toString()
in that result isNOT VALID ENCODED JSON
for all nodes (although is for some, likeNumberNode
s andBooleanNode
s). -
asString
Description copied from class:JsonNode
Similar toJsonNode.asString()
, but instead of throwing an exception for non-coercible values, will return specified default value. -
asStringOpt
Description copied from class:JsonNode
Similar toJsonNode.asString()
, but instead of throwing an exception for non-coercible values, will returnOptional.empty()
.- Specified by:
asStringOpt
in classJsonNode
-
findPath
Description copied from class:JsonNode
Method similar toJsonNode.findValue(java.lang.String)
, but that will return a "missing node" instead of null if no field is found. Missing node is a specific kind of node for whichJsonNode.isMissingNode()
returns true; and all value access methods return empty or missing value. -
hashCode
public abstract int hashCode() -
required
Description copied from class:JsonNode
Method is functionally equivalent topath(propertyName).required()
and can be used to check that this node is anObjectNode
(that is, represents JSON Object value) and has value for specified property with keypropertyName
(but note that value may be explicit JSON null value). If this node is Object Node and has value for specified property, matching value is returned; otherwiseIllegalArgumentException
is thrown. -
required
Description copied from class:JsonNode
Method is functionally equivalent topath(index).required()
and can be used to check that this node is anArrayNode
(that is, represents JSON Array value) and has value for specifiedindex
(but note that value may be explicit JSON null value). If this node is Array Node and has value for specified index, value at index is returned; otherwiseIllegalArgumentException
is thrown. -
traverse
-
asToken
Method that can be used for efficient type detection when using stream abstraction for traversing nodes. Will return the firstJsonToken
that equivalent stream event would produce (for most nodes there is just one token but for structured/container types multiple) -
numberType
Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.- Specified by:
numberType
in interfaceTreeNode
-
withObject
public ObjectNode withObject(JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) Description copied from class:JsonNode
Method that can be called on Object or Array nodes, to access a Object-valued node pointed to by givenJsonPointer
, if such a node exists: or if not, an attempt is made to create one and return it. For example, on document{ "a" : { "b" : { "c" : 13 } } }
calling method withJsonPointer
of/a/b
would returnObjectNode
{ "c" : 13 }
In cases where path leads to "missing" nodes, a path is created. So, for example, on above document, and
JsonPointer
of/a/x
an emptyObjectNode
would be returned and the document would look like:{ "a" : { "b" : { "c" : 13 }, "x" : { } } }
Finally, if the path is incompatible with the document -- there is an existingJsonNode
through which expression cannot go -- a replacement is attempted if (and only if) conversion is allowed as peroverwriteMode
passed in. For example, with above document and expression of/a/b/c
, conversion is allowed if passingOverwriteMode.SCALARS
orOvewriteMode.ALL
, and resulting document would look like:{ "a" : { "b" : { "c" : { } }, "x" : { } } }
but if different modes (NONE
orNULLS
) is passed, an exception is thrown instead.- Overrides:
withObject
in classJsonNode
- Parameters:
ptr
- Pointer that indicates path to use forObjectNode
value to return (potentially creating one as necessary)overwriteMode
- Defines which node types may be converted in case of incompatibleJsonPointer
expression: if conversion not allowed,UnsupportedOperationException
is thrown.preferIndex
- When creating a path (for empty or replacement), and path contains segment that may be an array index (simple integer number like3
), whether to construct anArrayNode
(true
) orObjectNode
(false
). In latter case matching property with quoted number (like"3"
) is used within Object.- Returns:
ObjectNode
found or created
-
_withObject
protected ObjectNode _withObject(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) -
_withXxxVerifyReplace
protected void _withXxxVerifyReplace(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex, JsonNode toReplace) -
_withXxxMayReplace
-
withArray
public ArrayNode withArray(JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) Description copied from class:JsonNode
Method that can be called on Object or Array nodes, to access a Array-valued node pointed to by givenJsonPointer
, if such a node exists: or if not, an attempt is made to create one and return it. For example, on document{ "a" : { "b" : [ 1, 2 ] } }
calling method withJsonPointer
of/a/b
would returnArray
[ 1, 2 ]
In cases where path leads to "missing" nodes, a path is created. So, for example, on above document, and
JsonPointer
of/a/x
an emptyArrayNode
would be returned and the document would look like:{ "a" : { "b" : [ 1, 2 ], "x" : [ ] } }
Finally, if the path is incompatible with the document -- there is an existingJsonNode
through which expression cannot go -- a replacement is attempted if (and only if) conversion is allowed as peroverwriteMode
passed in. For example, with above document and expression of/a/b/0
, conversion is allowed if passingOverwriteMode.SCALARS
orOvewriteMode.ALL
, and resulting document would look like:{ "a" : { "b" : [ [ ], 2 ], "x" : [ ] } }
but if different modes (NONE
orNULLS
) is passed, an exception is thrown instead.- Overrides:
withArray
in classJsonNode
- Parameters:
ptr
- Pointer that indicates path to use forArrayNode
value to return (potentially creating it as necessary)overwriteMode
- Defines which node types may be converted in case of incompatibleJsonPointer
expression: if conversion not allowed, an exception is thrown.preferIndex
- When creating a path (for empty or replacement), and path contains segment that may be an array index (simple integer number like3
), whether to construct anArrayNode
(true
) orObjectNode
(false
). In latter case matching property with quoted number (like"3"
) is used within Object.- Returns:
ArrayNode
found or created
-
_withArray
protected ArrayNode _withArray(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) -
_asBoolean
Method sub-classes should override if they can produceboolean
values viaasBoolean()
-- if not, returnnull
(in which case appropriate error will be thrown or default value returned).- Returns:
- Coerced value if possible; otherwise
null
to indicate this node cannot be coerced.
-
_asString
Method sub-classes should override if they can produceString
values viaasString()
-- if not, returnnull
(in which case appropriate error will be thrown or default value returned).- Returns:
- Coerced value if possible; otherwise
null
to indicate this node cannot be coerced.
-
serialize
public abstract void serialize(JsonGenerator jgen, SerializationContext ctxt) throws JacksonException Method called to serialize node instances using given generator.- Specified by:
serialize
in interfaceJacksonSerializable
- Throws:
JacksonException
-
serializeWithType
public abstract void serializeWithType(JsonGenerator jgen, SerializationContext ctxt, TypeSerializer typeSer) throws JacksonException Type information is needed, even if JsonNode instances are "plain" JSON, since they may be mixed with other types.- Specified by:
serializeWithType
in interfaceJacksonSerializable
- Throws:
JacksonException
-
toString
Description copied from class:JsonNode
Method that will produce (as of Jackson 2.10) valid JSON using default settings of databind, as String. If you want other kinds of JSON output (or output formatted using one of other Jackson-supported data formats) make sure to useObjectMapper
orObjectWriter
to serialize an instance, for example:String json = objectMapper.writeValueAsString(rootNode);
Note: method defined as abstract to ensure all implementation classes explicitly implement method, instead of relying on
Object.toString()
definition. -
toPrettyString
Description copied from class:JsonNode
Alternative toJsonNode.toString()
that will serialize this node using Jackson default pretty-printer.- Overrides:
toPrettyString
in classJsonNode
-
_reportCoercionFail
-
_reportShortCoercionRangeFail
-
_reportIntCoercionRangeFail
-
_reportLongCoercionRangeFail
-
_reportFloatCoercionRangeFail
-
_reportDoubleCoercionRangeFail
-
_reportShortCoercionFractionFail
-
_reportIntCoercionFractionFail
-
_reportLongCoercionFractionFail
-
_reportBigIntegerCoercionFractionFail
-
_reportIntCoercionNaNFail
-
_reportLongCoercionNaNFail
-
_reportBigIntegerCoercionNaNFail
-
_reportBigDecimalCoercionNaNFail
-
_reportWrongNodeType
Helper method that throwsJsonNodeException
as a result of this node being of wrong type -
_jsonPointerIfValid
-
_valueDesc
Method for implementation classes to return a short description of contained value, to be used in error messages.
-