- All Implemented Interfaces:
Serializable
,Iterable<JsonNode>
,tools.jackson.core.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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected tools.jackson.core.JsonPointer
_jsonPointerIfValid
(String exprOrProperty) 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
_reportIntCoercionRangeFail
(String method) protected long
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
(tools.jackson.core.JsonPointer origPtr, tools.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) protected ObjectNode
_withObject
(tools.jackson.core.JsonPointer origPtr, tools.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) protected boolean
_withXxxMayReplace
(JsonNode node, JsonNode.OverwriteMode overwriteMode) protected void
_withXxxVerifyReplace
(tools.jackson.core.JsonPointer origPtr, tools.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex, JsonNode toReplace) boolean
Method that will try to convert value of this node to a Java boolean.boolean
asBoolean
(boolean defaultValue) Method that will try to convert value of this node to a Java boolean.asDecimal
(BigDecimal defaultValue) double
asDouble()
Method that will try to convert value of this node to a Java double.double
asDouble
(double defaultValue) Method that will try to convert value of this node to a Java double.int
asInt()
Method that will try to convert value of this node to a Java int.int
asInt
(int defaultValue) Method that will try to convert value of this node to a Java int.long
asLong()
Method that will try to convert value of this node to a Java long.long
asLong
(long defaultValue) Method that will try to convert value of this node to a Java long.Returns the text value of this node or the provideddefaultValue
if this node does not have a text value.abstract tools.jackson.core.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.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 a Javadouble
: 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 to Javadouble
.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 to Javalong
.Method similar toJsonNode.longValue()
, but that will return emptyOptionalLong
(OptionalLong.empty()
) if this node cannot be converted to Javalong
.tools.jackson.core.JsonParser.NumberType
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
(tools.jackson.core.JsonGenerator jgen, SerializationContext ctxt) Method called to serialize node instances using given generator.abstract void
serializeWithType
(tools.jackson.core.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.tools.jackson.core.JsonParser
traverse
(tools.jackson.core.ObjectReadContext readCtxt) withArray
(tools.jackson.core.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
(tools.jackson.core.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, asString, 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
-
Constructor Details
-
BaseJsonNode
protected BaseJsonNode()
-
-
Method Details
-
isMissingNode
public boolean isMissingNode()- Specified by:
isMissingNode
in interfacetools.jackson.core.TreeNode
- Overrides:
isMissingNode
in classJsonNode
-
isEmbeddedValue
public boolean isEmbeddedValue()- Specified by:
isEmbeddedValue
in interfacetools.jackson.core.TreeNode
-
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 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 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.
-
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 to Javalong
. -
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 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 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.
-
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
-
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 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()
- 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 to Javadouble
.- Specified by:
doubleValue
in classJsonNode
- 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
.- 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 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 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.
-
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
-
asDecimal
-
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 Java boolean. JSON booleans map naturally; integer numbers other than 0 map to true, and 0 maps to false and Strings 'true' and 'false' map to corresponding values.If representation cannot be converted to a boolean value (including structured types like Objects and Arrays), default value of false will be returned; no exceptions are thrown.
-
asBoolean
public boolean asBoolean(boolean defaultValue) Description copied from class:JsonNode
Method that will try to convert value of this node to a Java boolean. JSON booleans map naturally; integer numbers other than 0 map to true, and 0 maps to false and Strings 'true' and 'false' map to corresponding values.If representation cannot be converted to a boolean value (including structured types like Objects and Arrays), specified defaultValue will be returned; no exceptions are thrown.
-
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
Returns the text value of this node or the provideddefaultValue
if this node does not have a text value. Useful for nodes that areMissingNode
orNullNode
, ensuring a default value is returned instead of null or missing indicators. -
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
public tools.jackson.core.JsonParser traverse(tools.jackson.core.ObjectReadContext readCtxt) - Specified by:
traverse
in interfacetools.jackson.core.TreeNode
-
asToken
public abstract tools.jackson.core.JsonToken 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)- Specified by:
asToken
in interfacetools.jackson.core.TreeNode
-
numberType
public tools.jackson.core.JsonParser.NumberType numberType()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
-
withObject
public ObjectNode withObject(tools.jackson.core.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(tools.jackson.core.JsonPointer origPtr, tools.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) -
_withXxxVerifyReplace
protected void _withXxxVerifyReplace(tools.jackson.core.JsonPointer origPtr, tools.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex, JsonNode toReplace) -
_withXxxMayReplace
-
withArray
public ArrayNode withArray(tools.jackson.core.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(tools.jackson.core.JsonPointer origPtr, tools.jackson.core.JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) -
serialize
public abstract void serialize(tools.jackson.core.JsonGenerator jgen, SerializationContext ctxt) throws tools.jackson.core.JacksonException Method called to serialize node instances using given generator.- Specified by:
serialize
in interfaceJacksonSerializable
- Throws:
tools.jackson.core.JacksonException
-
serializeWithType
public abstract void serializeWithType(tools.jackson.core.JsonGenerator jgen, SerializationContext ctxt, TypeSerializer typeSer) throws tools.jackson.core.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:
tools.jackson.core.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
-
_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.
-