java.lang.Object
tools.jackson.databind.JacksonSerializable.Base
tools.jackson.databind.JsonNode
tools.jackson.databind.node.BaseJsonNode
tools.jackson.databind.node.ValueNode
tools.jackson.databind.node.StringNode
- All Implemented Interfaces:
Serializable
,Iterable<JsonNode>
,TreeNode
,JacksonSerializable
Value node that contains a String value.
- 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
FieldsFields inherited from class tools.jackson.databind.node.ValueNode
BD_MAX_INTEGER, BD_MAX_LONG, BD_MAX_SHORT, BD_MIN_INTEGER, BD_MIN_LONG, BD_MIN_SHORT, BI_MAX_INTEGER, BI_MAX_LONG, BI_MAX_SHORT, BI_MIN_INTEGER, BI_MIN_LONG, BI_MIN_SHORT, MISSING
Fields inherited from class tools.jackson.databind.node.BaseJsonNode
OPT_FALSE, OPT_TRUE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMethod sub-classes should override if they can produceboolean
values viaBaseJsonNode.asBoolean()
-- 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 viaBaseJsonNode.asString()
-- if not, returnnull
(in which case appropriate error will be thrown or default value returned).protected BigDecimal
protected BigInteger
protected Double
protected Float
protected Integer
protected Long
protected Short
protected String
Method for implementation classes to return a short description of contained value, to be used in error messages.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
.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
.float
asFloat()
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 valuesfloat
asFloat
(float defaultValue) Method similar toJsonNode.asFloat()
, but that will returndefaultValue
if this node cannot be coerced tofloat
.Method similar toJsonNode.asFloat()
, but that will return (Optional.empty()
) if this node cannot be coerced tofloat
.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
.short
asShort()
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 inshort
range).short
asShort
(short defaultValue) Method similar toJsonNode.shortValue()
, but that will return specifieddefaultValue
if 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()
.asToken()
Method that can be used for efficient type detection when using stream abstraction for traversing nodes.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.deepCopy()
All current value nodes are immutable, so we can just return them as is.boolean
Equality for node objects is defined as full (deep) value equality.byte[]
getBinaryValue
(Base64Variant b64variant) Method for accessing content String assuming they were base64 encoded; if so, content is decoded and resulting binary data is returned.Return the type of this nodeint
hashCode()
final void
serialize
(JsonGenerator g, SerializationContext provider) Method called to serialize node instances using given generator.Method that will try to access value of this node as a JavaString
which works if (and only if) node contains JSON String ornull
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 (NOTE: JSON null is not considered a String here)static StringNode
Factory method that should be used to construct instances.Methods inherited from class tools.jackson.databind.node.ValueNode
_at, findParent, findParents, findValue, findValues, findValuesAsString, get, get, has, has, hasNonNull, hasNonNull, isEmpty, path, path, serializeWithType
Methods inherited from class tools.jackson.databind.node.BaseJsonNode
_jsonPointerIfValid, _reportBigDecimalCoercionNaNFail, _reportBigIntegerCoercionFractionFail, _reportBigIntegerCoercionNaNFail, _reportCoercionFail, _reportDoubleCoercionRangeFail, _reportFloatCoercionRangeFail, _reportIntCoercionFractionFail, _reportIntCoercionNaNFail, _reportIntCoercionRangeFail, _reportLongCoercionFractionFail, _reportLongCoercionNaNFail, _reportLongCoercionRangeFail, _reportShortCoercionFractionFail, _reportShortCoercionRangeFail, _reportWrongNodeType, _withArray, _withObject, _withXxxMayReplace, _withXxxVerifyReplace, asBoolean, asBoolean, asBooleanOpt, bigIntegerValue, bigIntegerValue, bigIntegerValueOpt, booleanValue, booleanValue, booleanValueOpt, decimalValue, decimalValue, decimalValueOpt, doubleValue, doubleValue, doubleValueOpt, findPath, floatValue, floatValue, floatValueOpt, intValue, intValue, intValueOpt, isEmbeddedValue, isMissingNode, longValue, longValue, longValueOpt, numberType, numberValue, required, required, shortValue, shortValue, shortValueOpt, toPrettyString, toString, traverse, withArray, withObject
Methods inherited from class tools.jackson.databind.JsonNode
_reportRequiredViolation, _reportUnsupportedOperation, _this, asOptional, asText, asText, at, at, canConvertToExactIntegral, canConvertToInt, canConvertToLong, canConvertToShort, equals, findParents, findValues, findValuesAsString, forEachEntry, isArray, isBigDecimal, isBigInteger, isBinary, isBoolean, isContainer, isDouble, isFloat, isFloatingPointNumber, isInt, isIntegralNumber, isLong, isNull, isNumber, isObject, isPojo, isShort, isString, isTextual, isValueNode, iterator, optional, optional, properties, propertyNames, propertyStream, require, requiredAt, requiredAt, requireNonNull, size, spliterator, textValue, values, valueStream, withArray, withArray, withArray, withArrayProperty, withObject, withObject, withObject, withObjectProperty
Methods inherited from class tools.jackson.databind.JacksonSerializable.Base
isEmpty
-
Field Details
-
_value
-
-
Constructor Details
-
StringNode
-
-
Method Details
-
valueOf
Factory method that should be used to construct instances. For some common cases, can reuse canonical instances: currently this is the case for empty Strings, in future possible for others as well. If null is passed, will return null.- Returns:
- Resulting
StringNode
object, if v is NOT null; null if it is.
-
getNodeType
Description copied from class:JsonNode
Return the type of this node- Specified by:
getNodeType
in classJsonNode
- Returns:
- the node type as a
JsonNodeType
enum value
-
asToken
Description copied from class:BaseJsonNode
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) -
_valueDesc
Description copied from class:BaseJsonNode
Method for implementation classes to return a short description of contained value, to be used in error messages.- Specified by:
_valueDesc
in classBaseJsonNode
-
deepCopy
Description copied from class:ValueNode
All current value nodes are immutable, so we can just return them as is. -
_asBoolean
Description copied from class:BaseJsonNode
Method sub-classes should override if they can produceboolean
values viaBaseJsonNode.asBoolean()
-- if not, returnnull
(in which case appropriate error will be thrown or default value returned).- Overrides:
_asBoolean
in classBaseJsonNode
- Returns:
- Coerced value if possible; otherwise
null
to indicate this node cannot be coerced.
-
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 ornull
value: if not, aJsonNodeException
will be thrown. In case of JSONnull
, Javanull
is returned.NOTE: for more conversions, use
JsonNode.asString()
instead.NOTE: in Jackson 2.x, this method was named
textValue()
.- Overrides:
stringValue
in classBaseJsonNode
- Returns:
String
value this node represents (if JSON String),null
for JSONnull
-
stringValue
Description copied from class:JsonNode
Method similar toJsonNode.stringValue()
, but that will return specifieddefaultValue
if this node does not contain a JSON String. This default value case includes JSONnull
.- Overrides:
stringValue
in classBaseJsonNode
- 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 -- only returnsnull
ifdefaultValue
isnull
-
stringValueOpt
Description copied from class:JsonNode
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)- Overrides:
stringValueOpt
in classBaseJsonNode
- Returns:
Optional<String>
value (if node represents JSON String);Optional.empty()
otherwise (including for JSON null)
-
_asString
Description copied from class:BaseJsonNode
Method sub-classes should override if they can produceString
values viaBaseJsonNode.asString()
-- if not, returnnull
(in which case appropriate error will be thrown or default value returned).- Overrides:
_asString
in classBaseJsonNode
- Returns:
- Coerced value if possible; otherwise
null
to indicate this node cannot be coerced.
-
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).- Overrides:
asString
in classBaseJsonNode
- Returns:
- String representation of this node, if coercible; exception otherwise
-
asString
Description copied from class:JsonNode
Similar toJsonNode.asString()
, but instead of throwing an exception for non-coercible values, will return specified default value.- Overrides:
asString
in classBaseJsonNode
-
asStringOpt
Description copied from class:JsonNode
Similar toJsonNode.asString()
, but instead of throwing an exception for non-coercible values, will returnOptional.empty()
.- Overrides:
asStringOpt
in classBaseJsonNode
-
getBinaryValue
Method for accessing content String assuming they were base64 encoded; if so, content is decoded and resulting binary data is returned.- Throws:
JsonNodeException
- if String contents are not valid Base64 encoded contentJacksonException
-
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()
.- Overrides:
binaryValue
in classBaseJsonNode
- Returns:
- Binary value this node represents (if node contains binary value)
- Throws:
JsonNodeException
- if node does not contain a Binary value (aJacksonException
-
asShort
public short asShort()Description copied from class:JsonNode
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 for
JsonNode.shortValue()
) will be truncated toshort
(if (and only if) they fit inshort
range). - JSON Strings that represent JSON Numbers ("stringified" numbers)
- JSON Null (converted to
0
)) - POJO nodes that contain Number values
- Overrides:
asShort
in classBaseJsonNode
- Returns:
short
value this node represents, if possible to accurately represent
- JSON Floating-point numbers with fractions (ones without fractions
are ok for
-
asShort
public short asShort(short defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.shortValue()
, but that will return specifieddefaultValue
if this node cannot be converted toshort
.- Overrides:
asShort
in classBaseJsonNode
- Parameters:
defaultValue
- Value to return if this node cannot be converted toshort
- Returns:
short
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
asShortOpt
Description copied from class:JsonNode
Method similar toJsonNode.asShort()
, but that will return (Optional.empty()
) if this node cannot be coerced toshort
.- Overrides:
asShortOpt
in classBaseJsonNode
- Returns:
Optional<Short>
value this node represents, if possible to accurately represent;Optional.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
- Overrides:
asInt
in classBaseJsonNode
- Returns:
int
value this node represents, if possible to accurately represent
- 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
.- Overrides:
asInt
in classBaseJsonNode
- Parameters:
defaultValue
- Value to return if this node cannot be converted toint
- Returns:
int
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
asIntOpt
Description copied from class:JsonNode
Method similar toJsonNode.asInt()
, but that will return (OptionalInt.empty()
) if this node cannot be coerced toint
.- Overrides:
asIntOpt
in classBaseJsonNode
- Returns:
OptionalInt
value this node represents, if possible to accurately represent;OptionalInt.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
- Overrides:
asLong
in classBaseJsonNode
- Returns:
long
value this node represents, if possible to accurately represent
- 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).- Overrides:
asLong
in classBaseJsonNode
- Parameters:
defaultValue
- Value to return if this node cannot be coerced tolong
- Returns:
long
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
asLongOpt
Description copied from class:JsonNode
Method similar toJsonNode.asLong()
, but that will return (OptionalLong.empty()
) if this node cannot be coerced tolong
.- Overrides:
asLongOpt
in classBaseJsonNode
- Returns:
OptionalLong
value this node represents (or can be coerced to),OptionalLong.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
- Overrides:
asBigInteger
in classBaseJsonNode
- 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
.- Overrides:
asBigInteger
in classBaseJsonNode
- 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
.- Overrides:
asBigIntegerOpt
in classBaseJsonNode
- Returns:
BigInteger
value this node represents, asOptional<BigInteger>
, if possible to accurately represent;Optional.empty()
otherwise.
-
asFloat
public float asFloat()Description copied from class:JsonNode
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 to
0.0f
) - POJO nodes that contain Number values
- Overrides:
asFloat
in classBaseJsonNode
- Returns:
float
value this node represents, if possible to accurately represent
-
asFloat
public float asFloat(float defaultValue) Description copied from class:JsonNode
Method similar toJsonNode.asFloat()
, but that will returndefaultValue
if this node cannot be coerced tofloat
.- Overrides:
asFloat
in classBaseJsonNode
- Returns:
float
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
asFloatOpt
Description copied from class:JsonNode
Method similar toJsonNode.asFloat()
, but that will return (Optional.empty()
) if this node cannot be coerced tofloat
.- Overrides:
asFloatOpt
in classBaseJsonNode
- Returns:
Optional<Float>
value this node represents, if possible to accurately represent;Optional.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
- Overrides:
asDouble
in classBaseJsonNode
- Returns:
double
value this node represents, if possible to accurately represent
-
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
.- Overrides:
asDouble
in classBaseJsonNode
- Returns:
double
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
asDoubleOpt
Description copied from class:JsonNode
Method similar toJsonNode.asDouble()
, but that will return (OptionalDouble.empty()
) if this node cannot be coerced todouble
.- Overrides:
asDoubleOpt
in classBaseJsonNode
- Returns:
OptionalDouble
value this node represents, if possible to accurately represent;OptionalDouble.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
- Overrides:
asDecimal
in classBaseJsonNode
- 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
.- Overrides:
asDecimal
in classBaseJsonNode
- Returns:
BigDecimal
value this node represents, if possible to accurately represent;defaultValue
otherwise
-
asDecimalOpt
Description copied from class:JsonNode
Method similar toJsonNode.asDecimal()
, but that will return emptyOptional
(Optional.empty()
) if this node cannot be coerced toBigDecimal
.- Overrides:
asDecimalOpt
in classBaseJsonNode
- Returns:
- Java
BigDecimal
value this node represents, asOptional<BigDecimal>
, if possible to accurately represent;Optional.empty()
otherwise
-
_tryParseAsShort
-
_tryParseAsInteger
-
_tryParseAsLong
-
_tryParseAsBigInteger
-
_tryParseAsFloat
-
_tryParseAsDouble
-
_tryParseAsBigDecimal
-
serialize
Description copied from class:BaseJsonNode
Method called to serialize node instances using given generator.- Specified by:
serialize
in interfaceJacksonSerializable
- Specified by:
serialize
in classBaseJsonNode
- Throws:
JacksonException
-
equals
Description copied from class:JsonNode
Equality for node objects is defined as full (deep) value equality. This means that it is possible to compare complete JSON trees for equality by comparing equality of root nodes.Note: marked as abstract to ensure all implementation classes define it properly and not rely on definition from
Object
. -
hashCode
public int hashCode()- Specified by:
hashCode
in classBaseJsonNode
-