- 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.OverwriteModeNested classes/interfaces inherited from interface tools.jackson.databind.JacksonSerializable
JacksonSerializable.Base -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected BooleanMethod sub-classes should override if they can producebooleanvalues viaasBoolean()-- if not, returnnull(in which case appropriate error will be thrown or default value returned).protected StringMethod sub-classes should override if they can produceStringvalues viaasString()-- if not, returnnull(in which case appropriate error will be thrown or default value returned).protected JsonPointer_jsonPointerIfValid(String exprOrProperty) protected BigDecimalprotected BigIntegerprotected BigIntegerprotected <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 longprotected long_reportLongCoercionNaNFail(String method) protected long_reportLongCoercionRangeFail(String method) protected shortprotected short_reportShortCoercionRangeFail(String method) protected <T> T_reportWrongNodeType(String msgTemplate, Object... args) Helper method that throwsJsonNodeExceptionas a result of this node being of wrong typeprotected abstract StringMethod 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 specifieddefaultValueif 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.booleanMethod that will try to convert value of this node to a Javaboolean.booleanasBoolean(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, aJsonNodeExceptionwill be thrown.asDecimal(BigDecimal defaultValue) Method similar toJsonNode.asDecimal(), but that will returndefaultValueif 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.doubleasDouble()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 valuesdoubleasDouble(double defaultValue) Method similar toJsonNode.asDouble(), but that will returndefaultValueif this node cannot be coerced todouble.Method similar toJsonNode.asDouble(), but that will return (OptionalDouble.empty()) if this node cannot be coerced todouble.floatasFloat()Method similar toJsonNode.floatValue()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.0f) POJO nodes that contain Number valuesfloatasFloat(float defaultValue) Method similar toJsonNode.asFloat(), but that will returndefaultValueif this node cannot be coerced tofloat.Method similar toJsonNode.asFloat(), but that will return (Optional.empty()) if this node cannot be coerced tofloat.intasInt()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 inintrange).intasInt(int defaultValue) Method similar toJsonNode.intValue(), but that will return specifieddefaultValueif this node cannot be converted toint.asIntOpt()Method similar toJsonNode.asInt(), but that will return (OptionalInt.empty()) if this node cannot be coerced toint.longasLong()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 inlongrange).longasLong(long defaultValue) Method similar toJsonNode.asLong(), but that will return specifieddefaultValueif 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.shortasShort()Method similar toJsonNode.shortValue()but in addition to coercing Number values (same asJsonNode.shortValue()), will also try to coerce a couple of additional types (or cases): JSON Floating-point numbers with fractions (ones without fractions are ok forJsonNode.shortValue()) will be truncated toshort(if (and only if) they fit inshortrange).shortasShort(short defaultValue) Method similar toJsonNode.shortValue(), but that will return specifieddefaultValueif this node cannot be converted toshort.Method similar toJsonNode.asShort(), but that will return (Optional.empty()) if this node cannot be coerced toshort.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 JsonTokenasToken()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, aJsonNodeExceptionwill be thrown.bigIntegerValue(BigInteger defaultValue) Method similar toJsonNode.bigIntegerValue(), but that will return specifieddefaultValueif 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, aJsonNodeExceptionwill be thrown.booleanMethod that will try to access value of this node as a Javabooleanwhich works if (and only if) node contains JSON boolean value: if not, aJsonNodeExceptionwill be thrown.booleanbooleanValue(boolean defaultValue) Method similar toJsonNode.booleanValue(), but that will return specifieddefaultValueif 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, aJsonNodeExceptionwill be thrown.decimalValue(BigDecimal defaultValue) Method similar toJsonNode.decimalValue(), but that will returndefaultValueif 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.doubleMethod that will try to access value of this node as adouble: but if node value cannot be expressed exactly as adouble, aJsonNodeExceptionwill be thrown.doubledoubleValue(double defaultValue) Method similar toJsonNode.doubleValue(), but that will return specifieddefaultValueif 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 JsonNodeMethod similar toJsonNode.findValue(java.lang.String), but that will return a "missing node" instead of null if no field is found.floatMethod that will try to access value of this node as a Javafloat: but if node value cannot be expressed exactly as afloat, aJsonNodeExceptionwill be thrown.floatfloatValue(float defaultValue) Method similar toJsonNode.floatValue(), but that will return specifieddefaultValueif this node cannot be converted tofloat.Method similar toJsonNode.floatValue(), but that will return emptyOptional<Float>(Optional.empty()) if this node cannot be converted to Javafloat.abstract inthashCode()intintValue()Method that will try to access value of this node as a Javaint: but if node value cannot be expressed exactly as anint, aJsonNodeExceptionwill be thrown.intintValue(int defaultValue) Method similar toJsonNode.intValue(), but that will return specifieddefaultValueif 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.booleanbooleanlongMethod that will try to access value of this node as a Javalong: but if node value cannot be expressed exactly as along, aJsonNodeExceptionwill be thrown.longlongValue(long defaultValue) Method similar toJsonNode.longValue(), but that will return specifieddefaultValueif 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 asNumberthat accurately represents its value, if (and only if) this is a number node (returnstrueforJsonNode.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 voidserialize(JsonGenerator jgen, SerializationContext ctxt) Method called to serialize node instances using given generator.abstract voidserializeWithType(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.shortMethod 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, aJsonNodeExceptionwill be thrown.shortshortValue(short defaultValue) Method similar toJsonNode.shortValue(), but that will return specifieddefaultValueif this node cannot be converted to Javashort.Method similar toJsonNode.shortValue(), but that will return emptyOptional<Short>(Optional.empty()) if this node cannot be converted to Javashort.Method that will try to access value of this node as a JavaStringwhich works if (and only if) node contains JSON String ornullvalue: if not, aJsonNodeExceptionwill be thrown.stringValue(String defaultValue) Method similar toJsonNode.stringValue(), but that will return specifieddefaultValueif 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 (NOTE: JSON null is not considered a String here)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, canConvertToShort, 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, withObjectPropertyMethods 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:
isMissingNodein interfaceTreeNode- Overrides:
isMissingNodein classJsonNode
-
isEmbeddedValue
public boolean isEmbeddedValue()- Specified by:
isEmbeddedValuein interfaceTreeNode
-
numberValue
Description copied from class:JsonNodeMethod that will try to access value of this node asNumberthat accurately represents its value, if (and only if) this is a number node (returnstrueforJsonNode.isNumber()). If this node is NOT a number node, aJsonNodeExceptionwill be thrown.- Specified by:
numberValuein classJsonNode- Returns:
- Number value this node contains, if numeric node
-
shortValue
public short shortValue()Description copied from class:JsonNodeMethod 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, aJsonNodeExceptionwill be thrown. Access works for following cases:- JSON Integer values that fit in Java 16-bit signed
shortrange - JSON Floating-point values that fit in Java 16-bit signed
shortrange AND do not have fractional part.
- Specified by:
shortValuein classJsonNode- Returns:
Shortvalue this node represents, if possible to accurately represent
- JSON Integer values that fit in Java 16-bit signed
-
shortValue
public short shortValue(short defaultValue) Description copied from class:JsonNodeMethod similar toJsonNode.shortValue(), but that will return specifieddefaultValueif this node cannot be converted to Javashort.- Specified by:
shortValuein classJsonNode- Parameters:
defaultValue- Value to return if this node cannot be converted to Javashort- Returns:
- Java
shortvalue this node represents, if possible to accurately represent;defaultValueotherwise
-
shortValueOpt
Description copied from class:JsonNodeMethod similar toJsonNode.shortValue(), but that will return emptyOptional<Short>(Optional.empty()) if this node cannot be converted to Javashort.- Specified by:
shortValueOptin classJsonNode- Returns:
- Java
shortvalue this node represents, asOptional<Short>, if possible to accurately represent;Optional.empty()otherwise
-
asShort
public short asShort()Description copied from class:JsonNodeMethod similar toJsonNode.shortValue()but in addition to coercing Number values (same asJsonNode.shortValue()), 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.shortValue()) will be truncated toshort(if (and only if) they fit inshortrange). - 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
-
asShort
public short asShort(short defaultValue) Description copied from class:JsonNodeMethod similar toJsonNode.shortValue(), but that will return specifieddefaultValueif this node cannot be converted toshort. -
asShortOpt
Description copied from class:JsonNodeMethod similar toJsonNode.asShort(), but that will return (Optional.empty()) if this node cannot be coerced toshort.- Specified by:
asShortOptin classJsonNode- Returns:
Optional<Short>value this node represents, if possible to accurately represent;Optional.empty()otherwise
-
intValue
public int intValue()Description copied from class:JsonNodeMethod that will try to access value of this node as a Javaint: but if node value cannot be expressed exactly as anint, aJsonNodeExceptionwill be thrown. Access works for following cases:- JSON Integer values that fit in Java 32-bit signed
intrange - JSON Floating-point values that fit in Java 32-bit signed
intrange 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:JsonNodeMethod similar toJsonNode.intValue(), but that will return specifieddefaultValueif this node cannot be converted to Javaint. -
intValueOpt
Description copied from class:JsonNodeMethod similar toJsonNode.intValue(), but that will return emptyOptionalInt(OptionalInt.empty()) if this node cannot be converted to Javaint.- Specified by:
intValueOptin classJsonNode- Returns:
- Java
intvalue this node represents, asOptionalInt, if possible to accurately represent;OptionalInt.empty()otherwise
-
asInt
public int asInt()Description copied from class:JsonNodeMethod 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 inintrange). - 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:JsonNodeMethod similar toJsonNode.intValue(), but that will return specifieddefaultValueif this node cannot be converted toint. -
asIntOpt
Description copied from class:JsonNodeMethod similar toJsonNode.asInt(), but that will return (OptionalInt.empty()) if this node cannot be coerced toint.- Specified by:
asIntOptin classJsonNode- Returns:
OptionalIntvalue this node represents, if possible to accurately represent;OptionalInt.empty()otherwise
-
longValue
public long longValue()Description copied from class:JsonNodeMethod that will try to access value of this node as a Javalong: but if node value cannot be expressed exactly as along, aJsonNodeExceptionwill be thrown. Access works for following cases:- JSON Integer values that fit in Java 64-bit signed
longrange - JSON Floating-point values that fit in Java 64-bit signed
longrange 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:JsonNodeMethod similar toJsonNode.longValue(), but that will return specifieddefaultValueif this node cannot be converted tolong. -
longValueOpt
Description copied from class:JsonNodeMethod similar toJsonNode.longValue(), but that will return emptyOptionalLong(OptionalLong.empty()) if this node cannot be converted to Javalong.- Specified by:
longValueOptin classJsonNode- Returns:
- Java
longvalue this node represents, asOptionalLong, if possible to accurately represent;OptionalLong.empty()otherwise
-
asLong
public long asLong()Description copied from class:JsonNodeMethod 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 inlongrange). - 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:JsonNodeMethod similar toJsonNode.asLong(), but that will return specifieddefaultValueif this node cannot be coerced tolong(instead of throwing an exception). -
asLongOpt
Description copied from class:JsonNodeMethod similar toJsonNode.asLong(), but that will return (OptionalLong.empty()) if this node cannot be coerced tolong.- Specified by:
asLongOptin classJsonNode- Returns:
OptionalLongvalue this node represents (or can be coerced to),OptionalLong.empty()otherwise
-
bigIntegerValue
Description copied from class:JsonNodeMethod that will try to access value of this node as aBigInteger, but if node value cannot be expressed exactly as aBigInteger, aJsonNodeExceptionwill be thrown. Access works for following cases:- JSON Integer values
- JSON Floating-point values that do not have fractional part.
- Specified by:
bigIntegerValuein classJsonNode- Returns:
BigIntegervalue this node represents, if possible to accurately represent
-
bigIntegerValue
Description copied from class:JsonNodeMethod similar toJsonNode.bigIntegerValue(), but that will return specifieddefaultValueif this node cannot be converted to JavaBigInteger.- Specified by:
bigIntegerValuein classJsonNode- Parameters:
defaultValue- Value to return if this node cannot be converted to JavaBigInteger- Returns:
- Java
BigIntegervalue this node represents, if possible to accurately represent;defaultValueotherwise
-
bigIntegerValueOpt
Description copied from class:JsonNodeMethod similar toJsonNode.bigIntegerValue(), but that will return empty (Optional.empty()) if this node cannot be converted to JavaBigInteger.- Specified by:
bigIntegerValueOptin classJsonNode- Returns:
- Java
BigIntegervalue this node represents, asOptional<BigInteger>, if possible to accurately represent;Optional.empty()otherwise
-
asBigInteger
Description copied from class:JsonNodeMethod 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:
asBigIntegerin classJsonNode- Returns:
BigIntegervalue this node represents, if possible to accurately convert;defaultValueotherwise
- JSON Floating-point numbers with fractions (ones without fractions
are ok for
-
asBigInteger
Description copied from class:JsonNodeMethod similar toJsonNode.asBigInteger(), but that will return specifieddefaultValueif this node cannot be converted toBigInteger.- Specified by:
asBigIntegerin classJsonNode- Parameters:
defaultValue- Value to return if this node cannot be converted toBigInteger- Returns:
BigIntegervalue this node represents, if possible to accurately convert;defaultValueotherwise
-
asBigIntegerOpt
Description copied from class:JsonNodeMethod similar toJsonNode.bigIntegerValue(), but that will return empty (Optional.empty()) if this node cannot be converted to JavaBigInteger.- Specified by:
asBigIntegerOptin classJsonNode- Returns:
BigIntegervalue this node represents, asOptional<BigInteger>, if possible to accurately represent;Optional.empty()otherwise.
-
floatValue
public float floatValue()Description copied from class:JsonNodeMethod that will try to access value of this node as a Javafloat: but if node value cannot be expressed exactly as afloat, aJsonNodeExceptionwill be thrown. Access works for following cases:- JSON Floating-point values that fit in Java 32-bit
doublerange - JSON Integer values that fit in Java 32-bit
doublerange
- Specified by:
floatValuein classJsonNode- Returns:
Floatvalue this node represents, if possible to accurately represent
- JSON Floating-point values that fit in Java 32-bit
-
floatValue
public float floatValue(float defaultValue) Description copied from class:JsonNodeMethod similar toJsonNode.floatValue(), but that will return specifieddefaultValueif this node cannot be converted tofloat.- Specified by:
floatValuein classJsonNode- Parameters:
defaultValue- Value to return if this node cannot be converted tofloat- Returns:
floatvalue this node represents, if possible to accurately represent;defaultValueotherwise
-
floatValueOpt
Description copied from class:JsonNodeMethod similar toJsonNode.floatValue(), but that will return emptyOptional<Float>(Optional.empty()) if this node cannot be converted to Javafloat.- Specified by:
floatValueOptin classJsonNode- Returns:
- Java
floatvalue this node represents, asOptional<Float>, if possible to accurately represent;Optional.empty()otherwise
-
asFloat
public float asFloat()Description copied from class:JsonNodeMethod similar toJsonNode.floatValue()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.0f) - POJO nodes that contain Number values
-
asFloat
public float asFloat(float defaultValue) Description copied from class:JsonNodeMethod similar toJsonNode.asFloat(), but that will returndefaultValueif this node cannot be coerced tofloat. -
asFloatOpt
Description copied from class:JsonNodeMethod similar toJsonNode.asFloat(), but that will return (Optional.empty()) if this node cannot be coerced tofloat.- Specified by:
asFloatOptin classJsonNode- Returns:
Optional<Float>value this node represents, if possible to accurately represent;Optional.empty()otherwise
-
doubleValue
public double doubleValue()Description copied from class:JsonNodeMethod that will try to access value of this node as adouble: but if node value cannot be expressed exactly as adouble, aJsonNodeExceptionwill be thrown. Access works for following cases:- JSON Floating-point values that fit in Java 64-bit
doublerange - JSON Integer values that fit in Java 64-bit
doublerange
NOTE: for more lenient conversions, use
JsonNode.asDouble()- Specified by:
doubleValuein classJsonNode- Returns:
Doublevalue 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:JsonNodeMethod similar toJsonNode.doubleValue(), but that will return specifieddefaultValueif this node cannot be converted todouble.- Specified by:
doubleValuein classJsonNode- Parameters:
defaultValue- Value to return if this node cannot be converted todouble- Returns:
doublevalue this node represents, if possible to accurately represent;defaultValueotherwise
-
doubleValueOpt
Description copied from class:JsonNodeMethod similar toJsonNode.doubleValue(), but that will return emptyOptionalLong(OptionalDouble.empty()) if this node cannot be converted to Javadouble.- Specified by:
doubleValueOptin classJsonNode- Returns:
- Java
doublevalue this node represents, asOptionalDouble, if possible to accurately represent;OptionalDouble.empty()otherwise
-
asDouble
public double asDouble()Description copied from class:JsonNodeMethod 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:JsonNodeMethod similar toJsonNode.asDouble(), but that will returndefaultValueif this node cannot be coerced todouble. -
asDoubleOpt
Description copied from class:JsonNodeMethod similar toJsonNode.asDouble(), but that will return (OptionalDouble.empty()) if this node cannot be coerced todouble.- Specified by:
asDoubleOptin classJsonNode- Returns:
OptionalDoublevalue this node represents, if possible to accurately represent;OptionalDouble.empty()otherwise
-
decimalValue
Description copied from class:JsonNodeMethod that will try to access value of this node as a JavaBigDecimal: but if node value cannot be expressed exactly as aBigDecimal, aJsonNodeExceptionwill be thrown. Access works for following cases:- All JSON Number values
NOTE: for more lenient conversions, use
JsonNode.asDecimal()- Specified by:
decimalValuein classJsonNode- Returns:
BigDecimalvalue this node represents, if possible to accurately represent
-
decimalValue
Description copied from class:JsonNodeMethod similar toJsonNode.decimalValue(), but that will returndefaultValueif this node cannot be coerced to JavaBigDecimal.- Specified by:
decimalValuein classJsonNode- Returns:
BigDecimalvalue this node represents, if possible to accurately represent;defaultValueotherwise
-
decimalValueOpt
Description copied from class:JsonNodeMethod similar toJsonNode.decimalValue(), but that will return emptyOptional(Optional.empty()) if this node cannot be coerced toBigDecimal.- Specified by:
decimalValueOptin classJsonNode- Returns:
- Java
BigDecimalvalue this node represents, asOptional<BigDecimal>, if possible to accurately represent;Optional.empty()otherwise
-
asDecimal
Description copied from class:JsonNodeMethod that will try to access value of this node as aBigDecimal: but if node value cannot be expressed exactly as aBigDecimal, aJsonNodeExceptionwill 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:
asDecimalin classJsonNode- Returns:
BigDecimalvalue this node represents, if possible to accurately represent
-
asDecimal
Description copied from class:JsonNodeMethod similar toJsonNode.asDecimal(), but that will returndefaultValueif this node cannot be coerced to JavaBigDecimal. -
asDecimalOpt
Description copied from class:JsonNodeMethod similar toJsonNode.asDecimal(), but that will return emptyOptional(Optional.empty()) if this node cannot be coerced toBigDecimal.- Specified by:
asDecimalOptin classJsonNode- Returns:
- Java
BigDecimalvalue this node represents, asOptional<BigDecimal>, if possible to accurately represent;Optional.empty()otherwise
-
binaryValue
public byte[] binaryValue()Description copied from class:JsonNodeMethod 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, aJsonNodeExceptionwill be thrown. To check if this method can be used, you may callJsonNode.isBinary().- Specified by:
binaryValuein classJsonNode- Returns:
- Binary value this node represents (if node contains binary value)
-
booleanValue
public boolean booleanValue()Description copied from class:JsonNodeMethod that will try to access value of this node as a Javabooleanwhich works if (and only if) node contains JSON boolean value: if not, aJsonNodeExceptionwill be thrown.NOTE: for more lenient conversions, use
JsonNode.asBoolean()- Specified by:
booleanValuein classJsonNode- Returns:
booleanvalue this node represents (if JSON boolean)
-
booleanValue
public boolean booleanValue(boolean defaultValue) Description copied from class:JsonNodeMethod similar toJsonNode.booleanValue(), but that will return specifieddefaultValueif this node does not contain a JSON boolean.- Specified by:
booleanValuein classJsonNode- Parameters:
defaultValue- Value to return if this node does not contain a JSON boolean.- Returns:
- Java
booleanvalue this node represents (if JSON boolean);defaultValueotherwise
-
booleanValueOpt
Description copied from class:JsonNodeMethod similar toJsonNode.booleanValue(), but that will returnOptional.empty()if this node does not contain a JSON boolean.- Specified by:
booleanValueOptin classJsonNode- Returns:
Optional<Boolean>value (if node represents JSON boolean);Optional.empty()otherwise
-
asBoolean
public boolean asBoolean()Description copied from class:JsonNodeMethod 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;nullmaps to false and Strings 'true' and 'false' map to corresponding values. Other values (including structured types like Objects and Arrays) will result in aJsonNodeExceptionbeing thrown. -
asBoolean
public boolean asBoolean(boolean defaultValue) Description copied from class:JsonNodeSimilar toJsonNode.asBoolean(), but instead of throwing an exception for non-coercible values, will return specified default value. -
asBooleanOpt
Description copied from class:JsonNodeSimilar toJsonNode.asBoolean(), but instead of throwing an exception for non-coercible values, will returnOptional.empty().- Specified by:
asBooleanOptin classJsonNode
-
stringValue
Description copied from class:JsonNodeMethod that will try to access value of this node as a JavaStringwhich works if (and only if) node contains JSON String ornullvalue: if not, aJsonNodeExceptionwill be thrown. In case of JSONnull, Javanullis returned.NOTE: for more conversions, use
JsonNode.asString()instead.NOTE: in Jackson 2.x, this method was named
textValue().- Specified by:
stringValuein classJsonNode- Returns:
Stringvalue this node represents (if JSON String),nullfor JSONnull
-
stringValue
Description copied from class:JsonNodeMethod similar toJsonNode.stringValue(), but that will return specifieddefaultValueif this node does not contain a JSON String. This default value case includes JSONnull.- Specified by:
stringValuein classJsonNode- Parameters:
defaultValue- Value to return if this node does not contain a JSON String.- Returns:
- Java
Stringvalue this node represents (if JSON String);defaultValueotherwise -- only returnsnullifdefaultValueisnull
-
stringValueOpt
Description copied from class:JsonNodeMethod similar toJsonNode.stringValue(), but that will returnOptional.empty()if this node does not contain a JSON String (NOTE: JSON null is not considered a String here)- Specified by:
stringValueOptin classJsonNode- Returns:
Optional<String>value (if node represents JSON String);Optional.empty()otherwise (including for JSON null)
-
asString
Description copied from class:JsonNodeMethod 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); JSONnulls map to empty String. Other values (including structured types like Objects and Arrays, and "missing" value) will result in aJsonNodeExceptionbeing thrown.NOTE: this is NOT same as
JsonNode.toString()in that result isNOT VALID ENCODED JSON
for all nodes (although is for some, likeNumberNodes andBooleanNodes). -
asString
Description copied from class:JsonNodeSimilar toJsonNode.asString(), but instead of throwing an exception for non-coercible values, will return specified default value. -
asStringOpt
Description copied from class:JsonNodeSimilar toJsonNode.asString(), but instead of throwing an exception for non-coercible values, will returnOptional.empty().- Specified by:
asStringOptin classJsonNode
-
findPath
Description copied from class:JsonNodeMethod 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:JsonNodeMethod 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; otherwiseIllegalArgumentExceptionis thrown. -
required
Description copied from class:JsonNodeMethod 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; otherwiseIllegalArgumentExceptionis thrown. -
traverse
-
asToken
Method that can be used for efficient type detection when using stream abstraction for traversing nodes. Will return the firstJsonTokenthat 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:
numberTypein interfaceTreeNode
-
withObject
public ObjectNode withObject(JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) Description copied from class:JsonNodeMethod 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 withJsonPointerof/a/bwould returnObjectNode{ "c" : 13 }In cases where path leads to "missing" nodes, a path is created. So, for example, on above document, and
JsonPointerof/a/xan emptyObjectNodewould 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 existingJsonNodethrough which expression cannot go -- a replacement is attempted if (and only if) conversion is allowed as peroverwriteModepassed in. For example, with above document and expression of/a/b/c, conversion is allowed if passingOverwriteMode.SCALARSorOvewriteMode.ALL, and resulting document would look like:{ "a" : { "b" : { "c" : { } }, "x" : { } } }but if different modes (NONEorNULLS) is passed, an exception is thrown instead.- Overrides:
withObjectin classJsonNode- Parameters:
ptr- Pointer that indicates path to use forObjectNodevalue to return (potentially creating one as necessary)overwriteMode- Defines which node types may be converted in case of incompatibleJsonPointerexpression: if conversion not allowed,UnsupportedOperationExceptionis 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:
ObjectNodefound 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:JsonNodeMethod 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 withJsonPointerof/a/bwould returnArray[ 1, 2 ]
In cases where path leads to "missing" nodes, a path is created. So, for example, on above document, and
JsonPointerof/a/xan emptyArrayNodewould 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 existingJsonNodethrough which expression cannot go -- a replacement is attempted if (and only if) conversion is allowed as peroverwriteModepassed in. For example, with above document and expression of/a/b/0, conversion is allowed if passingOverwriteMode.SCALARSorOvewriteMode.ALL, and resulting document would look like:{ "a" : { "b" : [ [ ], 2 ], "x" : [ ] } }but if different modes (NONEorNULLS) is passed, an exception is thrown instead.- Overrides:
withArrayin classJsonNode- Parameters:
ptr- Pointer that indicates path to use forArrayNodevalue to return (potentially creating it as necessary)overwriteMode- Defines which node types may be converted in case of incompatibleJsonPointerexpression: 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:
ArrayNodefound or created
-
_withArray
protected ArrayNode _withArray(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex) -
_asBoolean
Method sub-classes should override if they can producebooleanvalues viaasBoolean()-- if not, returnnull(in which case appropriate error will be thrown or default value returned).- Returns:
- Coerced value if possible; otherwise
nullto indicate this node cannot be coerced.
-
_asString
Method sub-classes should override if they can produceStringvalues viaasString()-- if not, returnnull(in which case appropriate error will be thrown or default value returned).- Returns:
- Coerced value if possible; otherwise
nullto 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:
serializein 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:
serializeWithTypein interfaceJacksonSerializable- Throws:
JacksonException
-
toString
Description copied from class:JsonNodeMethod 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 useObjectMapperorObjectWriterto 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:JsonNodeAlternative toJsonNode.toString()that will serialize this node using Jackson default pretty-printer.- Overrides:
toPrettyStringin classJsonNode
-
_reportCoercionFail
-
_reportShortCoercionRangeFail
-
_reportIntCoercionRangeFail
-
_reportLongCoercionRangeFail
-
_reportFloatCoercionRangeFail
-
_reportDoubleCoercionRangeFail
-
_reportShortCoercionFractionFail
-
_reportIntCoercionFractionFail
-
_reportLongCoercionFractionFail
-
_reportBigIntegerCoercionFractionFail
-
_reportIntCoercionNaNFail
-
_reportLongCoercionNaNFail
-
_reportBigIntegerCoercionNaNFail
-
_reportBigDecimalCoercionNaNFail
-
_reportWrongNodeType
Helper method that throwsJsonNodeExceptionas 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.
-