Top Description Fields Constructors Methods
tools.jackson.databind.node

public abstract Class BaseJsonNode

extends JsonNode
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
tools.jackson.databind.node.ContainerNode, tools.jackson.databind.node.MissingNode, tools.jackson.databind.node.ValueNode
Imports
java.math.BigDecimal, .BigInteger, java.util.Optional, .OptionalDouble, .OptionalInt, .OptionalLong, tools.jackson.core.*, tools.jackson.databind.JacksonSerializable, .JsonNode, .SerializationContext, tools.jackson.databind.exc.JsonNodeException, tools.jackson.databind.jsontype.TypeSerializer, tools.jackson.databind.util.ClassUtil

Abstract base class common to all standard 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 java.io.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.

Field Summary

Modifier and TypeField and Description
protected static final Optional<Boolean>
protected static final Optional<Boolean>
private static final long

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected Boolean

Returns:

Coerced value if possible; otherwise null to indicate this node cannot be coerced.
_asBoolean
()

Method sub-classes should override if they can produce boolean values via asBoolean() -- if not, return null (in which case appropriate error will be thrown or default value returned).

protected String

Returns:

Coerced value if possible; otherwise null to indicate this node cannot be coerced.
_asString
()

Method sub-classes should override if they can produce String values via asString() -- if not, return null (in which case appropriate error will be thrown or default value returned).

protected JsonPointer
_jsonPointerIfValid(String exprOrProperty)

protected BigDecimal
protected BigInteger
protected BigInteger
protected <T> T
_reportCoercionFail(String method, Class<?> targetType, String message)

protected double
protected float
protected int
protected int
protected int
protected long
protected long
protected long
protected short
protected short
protected <T> T
_reportWrongNodeType(String msgTemplate, Object... args)

Helper method that throws JsonNodeException as a result of this node being of wrong type

protected abstract String
_valueDesc()

Method for implementation classes to return a short description of contained value, to be used in error messages.

protected ArrayNode
_withArray(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)

protected ObjectNode
_withObject(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)

protected boolean
protected void
_withXxxVerifyReplace(JsonPointer origPtr, JsonPointer currentPtr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex, JsonNode toReplace)

public BigInteger
asBigInteger()

Implements abstract tools.jackson.databind.JsonNode.asBigInteger.

Method similar to bigIntegerValue() but in addition to coercing Number values (same as 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 bigIntegerValue()) will be truncated to integer value (like with BigDecimal#toBigInteger()))
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
public BigInteger
asBigInteger(BigInteger defaultValue)

Implements abstract tools.jackson.databind.JsonNode.asBigInteger.

Method similar to asBigInteger(), but that will return specified defaultValue if this node cannot be converted to BigInteger.

public Optional<BigInteger>
asBigIntegerOpt()

Implements abstract tools.jackson.databind.JsonNode.asBigIntegerOpt.

Method similar to bigIntegerValue(), but that will return empty (Optional.empty()) if this node cannot be converted to Java BigInteger.

public boolean
asBoolean()

Implements abstract tools.jackson.databind.JsonNode.asBoolean.

Method that will try to convert value of this node to a Java boolean.

public boolean
asBoolean(boolean defaultValue)

Implements abstract tools.jackson.databind.JsonNode.asBoolean.

Similar to asBoolean(), but instead of throwing an exception for non-coercible values, will return specified default value.

public Optional<Boolean>
asBooleanOpt()

Implements abstract tools.jackson.databind.JsonNode.asBooleanOpt.

Similar to asBoolean(), but instead of throwing an exception for non-coercible values, will return Optional.empty().

public BigDecimal
asDecimal()

Implements abstract tools.jackson.databind.JsonNode.asDecimal.

Method that will try to access value of this node as a BigDecimal: but if node value cannot be expressed exactly as a BigDecimal, a JsonNodeException will be thrown.

public BigDecimal
asDecimal(BigDecimal defaultValue)

Implements abstract tools.jackson.databind.JsonNode.asDecimal.

Method similar to asDecimal(), but that will return defaultValue if this node cannot be coerced to Java BigDecimal.

public Optional<BigDecimal>
asDecimalOpt()

Implements abstract tools.jackson.databind.JsonNode.asDecimalOpt.

Method similar to asDecimal(), but that will return empty Optional (Optional.empty()) if this node cannot be coerced to BigDecimal.

public double
asDouble()

Implements abstract tools.jackson.databind.JsonNode.asDouble.

Method similar to 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
public double
asDouble(double defaultValue)

Implements abstract tools.jackson.databind.JsonNode.asDouble.

Method similar to asDouble(), but that will return defaultValue if this node cannot be coerced to double.

public OptionalDouble
asDoubleOpt()

Implements abstract tools.jackson.databind.JsonNode.asDoubleOpt.

Method similar to asDouble(), but that will return (OptionalDouble.empty()) if this node cannot be coerced to double.

public float
asFloat()

Implements abstract tools.jackson.databind.JsonNode.asFloat.

Method similar to 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
public float
asFloat(float defaultValue)

Implements abstract tools.jackson.databind.JsonNode.asFloat.

Method similar to asFloat(), but that will return defaultValue if this node cannot be coerced to float.

public Optional<Float>
asFloatOpt()

Implements abstract tools.jackson.databind.JsonNode.asFloatOpt.

Method similar to asFloat(), but that will return (Optional.empty()) if this node cannot be coerced to float.

public int
asInt()

Implements abstract tools.jackson.databind.JsonNode.asInt.

Method similar to intValue() but in addition to coercing Number values (same as 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 intValue()) will be truncated to int (if (and only if) they fit in int range).
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
public int
asInt(int defaultValue)

Implements abstract tools.jackson.databind.JsonNode.asInt.

Method similar to intValue(), but that will return specified defaultValue if this node cannot be converted to int.

public OptionalInt
asIntOpt()

Implements abstract tools.jackson.databind.JsonNode.asIntOpt.

Method similar to asInt(), but that will return (OptionalInt.empty()) if this node cannot be coerced to int.

public long
asLong()

Implements abstract tools.jackson.databind.JsonNode.asLong.

Method similar to longValue() but in addition to coercing Number values (same as 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 longValue()) will be truncated to long (if (and only if) they fit in long range).
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
public long
asLong(long defaultValue)

Implements abstract tools.jackson.databind.JsonNode.asLong.

Method similar to asLong(), but that will return specified defaultValue if this node cannot be coerced to long (instead of throwing an exception).

public OptionalLong
asLongOpt()

Implements abstract tools.jackson.databind.JsonNode.asLongOpt.

Method similar to asLong(), but that will return (OptionalLong.empty()) if this node cannot be coerced to long.

public short
asShort()

Implements abstract tools.jackson.databind.JsonNode.asShort.

Method similar to shortValue() but in addition to coercing Number values (same as 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 shortValue()) will be truncated to short (if (and only if) they fit in short range).
  • JSON Strings that represent JSON Numbers ("stringified" numbers)
  • JSON Null (converted to 0))
  • POJO nodes that contain Number values
public short
asShort(short defaultValue)

Implements abstract tools.jackson.databind.JsonNode.asShort.

Method similar to shortValue(), but that will return specified defaultValue if this node cannot be converted to short.

public Optional<Short>
asShortOpt()

Implements abstract tools.jackson.databind.JsonNode.asShortOpt.

Method similar to asShort(), but that will return (Optional.empty()) if this node cannot be coerced to short.

public String
asString()

Implements abstract tools.jackson.databind.JsonNode.asString.

Method that will try to convert value of this node to a String.

public String
asString(String defaultValue)

Implements abstract tools.jackson.databind.JsonNode.asString.

Similar to asString(), but instead of throwing an exception for non-coercible values, will return specified default value.

public Optional<String>
asStringOpt()

Implements abstract tools.jackson.databind.JsonNode.asStringOpt.

Similar to asString(), but instead of throwing an exception for non-coercible values, will return Optional.empty().

public abstract JsonToken
asToken()

Redeclares tools.jackson.core.TreeNode.asToken.

Method that can be used for efficient type detection when using stream abstraction for traversing nodes.

public BigInteger
bigIntegerValue()

Implements abstract tools.jackson.databind.JsonNode.bigIntegerValue.

Method that will try to access value of this node as a BigInteger, but if node value cannot be expressed exactly as a BigInteger, a JsonNodeException will be thrown.

public BigInteger
bigIntegerValue(BigInteger defaultValue)

Implements abstract tools.jackson.databind.JsonNode.bigIntegerValue.

Method similar to bigIntegerValue(), but that will return specified defaultValue if this node cannot be converted to Java BigInteger.

public Optional<BigInteger>
bigIntegerValueOpt()

Implements abstract tools.jackson.databind.JsonNode.bigIntegerValueOpt.

Method similar to bigIntegerValue(), but that will return empty (Optional.empty()) if this node cannot be converted to Java BigInteger.

public byte[]
binaryValue()

Implements abstract tools.jackson.databind.JsonNode.binaryValue.

Method that will try to access value of this node as binary value (Java byte[]) which works if (and only if) node contains binary value (for JSON, Base64-encoded String, for other formats native binary value): if not, a JsonNodeException will be thrown.

public boolean
booleanValue()

Implements abstract tools.jackson.databind.JsonNode.booleanValue.

Method that will try to access value of this node as a Java boolean which works if (and only if) node contains JSON boolean value: if not, a JsonNodeException will be thrown.

public boolean
booleanValue(boolean defaultValue)

Implements abstract tools.jackson.databind.JsonNode.booleanValue.

Method similar to booleanValue(), but that will return specified defaultValue if this node does not contain a JSON boolean.

public Optional<Boolean>
booleanValueOpt()

Implements abstract tools.jackson.databind.JsonNode.booleanValueOpt.

Method similar to booleanValue(), but that will return Optional.empty() if this node does not contain a JSON boolean.

public BigDecimal
decimalValue()

Implements abstract tools.jackson.databind.JsonNode.decimalValue.

Method that will try to access value of this node as a Java BigDecimal: but if node value cannot be expressed exactly as a BigDecimal, a JsonNodeException will be thrown.

public BigDecimal
decimalValue(BigDecimal defaultValue)

Implements abstract tools.jackson.databind.JsonNode.decimalValue.

Method similar to decimalValue(), but that will return defaultValue if this node cannot be coerced to Java BigDecimal.

public Optional<BigDecimal>
decimalValueOpt()

Implements abstract tools.jackson.databind.JsonNode.decimalValueOpt.

Method similar to decimalValue(), but that will return empty Optional (Optional.empty()) if this node cannot be coerced to BigDecimal.

public double
doubleValue()

Implements abstract tools.jackson.databind.JsonNode.doubleValue.

Method that will try to access value of this node as a double: but if node value cannot be expressed exactly as a double, a JsonNodeException will be thrown.

public double
doubleValue(double defaultValue)

Implements abstract tools.jackson.databind.JsonNode.doubleValue.

Method similar to doubleValue(), but that will return specified defaultValue if this node cannot be converted to double.

public OptionalDouble
doubleValueOpt()

Implements abstract tools.jackson.databind.JsonNode.doubleValueOpt.

Method similar to doubleValue(), but that will return empty OptionalLong (OptionalDouble.empty()) if this node cannot be converted to Java double.

public final JsonNode
findPath(String fieldName)

Implements abstract tools.jackson.databind.JsonNode.findPath.

Method similar to findValue, but that will return a "missing node" instead of null if no field is found.

public float
floatValue()

Implements abstract tools.jackson.databind.JsonNode.floatValue.

Method that will try to access value of this node as a Java float: but if node value cannot be expressed exactly as a float, a JsonNodeException will be thrown.

public float
floatValue(float defaultValue)

Implements abstract tools.jackson.databind.JsonNode.floatValue.

Method similar to floatValue(), but that will return specified defaultValue if this node cannot be converted to float.

public Optional<Float>
floatValueOpt()

Implements abstract tools.jackson.databind.JsonNode.floatValueOpt.

Method similar to floatValue(), but that will return empty Optional<Float> (Optional.empty()) if this node cannot be converted to Java float.

public abstract int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public int
intValue()

Implements abstract tools.jackson.databind.JsonNode.intValue.

Method that will try to access value of this node as a Java int: but if node value cannot be expressed exactly as an int, a JsonNodeException will be thrown.

public int
intValue(int defaultValue)

Implements abstract tools.jackson.databind.JsonNode.intValue.

Method similar to intValue(), but that will return specified defaultValue if this node cannot be converted to Java int.

public OptionalInt
intValueOpt()

Implements abstract tools.jackson.databind.JsonNode.intValueOpt.

Method similar to intValue(), but that will return empty OptionalInt (OptionalInt.empty()) if this node cannot be converted to Java int.

public boolean
isEmbeddedValue()

Implements tools.jackson.core.TreeNode.isEmbeddedValue.

Method that returns true if this node represents an embedded "foreign" (or perhaps native?) object (like POJO), not represented as regular content.

public boolean
isMissingNode()

Overrides tools.jackson.databind.JsonNode.isMissingNode.

Implements tools.jackson.core.TreeNode.isMissingNode.

Method that returns true for "virtual" nodes which represent missing entries constructed by path accessor methods when there is no actual node matching given criteria.

public long
longValue()

Implements abstract tools.jackson.databind.JsonNode.longValue.

Method that will try to access value of this node as a Java long: but if node value cannot be expressed exactly as a long, a JsonNodeException will be thrown.

public long
longValue(long defaultValue)

Implements abstract tools.jackson.databind.JsonNode.longValue.

Method similar to longValue(), but that will return specified defaultValue if this node cannot be converted to long.

public OptionalLong
longValueOpt()

Implements abstract tools.jackson.databind.JsonNode.longValueOpt.

Method similar to longValue(), but that will return empty OptionalLong (OptionalLong.empty()) if this node cannot be converted to Java long.

public JsonParser.NumberType
numberType()

Implements tools.jackson.core.TreeNode.numberType.

Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.

public Number
numberValue()

Implements abstract tools.jackson.databind.JsonNode.numberValue.

Method that will try to access value of this node as Number that accurately represents its value, if (and only if) this is a number node (returns true for isNumber).

public JsonNode
required(String fieldName)

Implements abstract tools.jackson.databind.JsonNode.required.

Method is functionally equivalent to path(propertyName).required() and can be used to check that this node is an ObjectNode (that is, represents JSON Object value) and has value for specified property with key propertyName (but note that value may be explicit JSON null value).

public JsonNode
required(int index)

Implements abstract tools.jackson.databind.JsonNode.required.

Method is functionally equivalent to path(index).required() and can be used to check that this node is an ArrayNode (that is, represents JSON Array value) and has value for specified index (but note that value may be explicit JSON null value).

public abstract void
serialize(JsonGenerator jgen, SerializationContext ctxt)

Redeclares tools.jackson.databind.JacksonSerializable.serialize.

Method called to serialize node instances using given generator.

public abstract void
serializeWithType(JsonGenerator jgen, SerializationContext ctxt, TypeSerializer typeSer)

Redeclares tools.jackson.databind.JacksonSerializable.serializeWithType.

Type information is needed, even if JsonNode instances are "plain" JSON, since they may be mixed with other types.

public short
shortValue()

Implements abstract tools.jackson.databind.JsonNode.shortValue.

Method that will try to access value of this node as 16-bit signed integer value (Java short): but if node value cannot be expressed exactly as a short, a JsonNodeException will be thrown.

public short
shortValue(short defaultValue)

Implements abstract tools.jackson.databind.JsonNode.shortValue.

Method similar to shortValue(), but that will return specified defaultValue if this node cannot be converted to Java short.

public Optional<Short>
shortValueOpt()

Implements abstract tools.jackson.databind.JsonNode.shortValueOpt.

Method similar to shortValue(), but that will return empty Optional<Short> (Optional.empty()) if this node cannot be converted to Java short.

public String
stringValue()

Implements abstract tools.jackson.databind.JsonNode.stringValue.

Method that will try to access value of this node as a Java String which works if (and only if) node contains JSON String or null value: if not, a JsonNodeException will be thrown.

public String
stringValue(String defaultValue)

Implements abstract tools.jackson.databind.JsonNode.stringValue.

Method similar to stringValue(), but that will return specified defaultValue if this node does not contain a JSON String.

public Optional<String>
stringValueOpt()

Implements abstract tools.jackson.databind.JsonNode.stringValueOpt.

Method similar to stringValue(), but that will return Optional.empty() if this node does not contain a JSON String (NOTE: JSON null is not considered a String here)

public String
toPrettyString()

Overrides tools.jackson.databind.JsonNode.toPrettyString.

Alternative to toString that will serialize this node using Jackson default pretty-printer.

public String
toString()

Implements abstract tools.jackson.databind.JsonNode.toString.

Method that will produce (as of Jackson 2.10) valid JSON using default settings of databind, as String.

public JsonParser
traverse(ObjectReadContext readCtxt)

Implements tools.jackson.core.TreeNode.traverse.

Method for constructing a JsonParser instance for iterating over contents of the tree that this node is root of.

public ArrayNode
withArray(JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)

Overrides tools.jackson.databind.JsonNode.withArray.

Method that can be called on Object or Array nodes, to access a Array-valued node pointed to by given JsonPointer, if such a node exists: or if not, an attempt is made to create one and return it.

public ObjectNode
withObject(JsonPointer ptr, JsonNode.OverwriteMode overwriteMode, boolean preferIndex)

Overrides tools.jackson.databind.JsonNode.withObject.

Method that can be called on Object or Array nodes, to access a Object-valued node pointed to by given JsonPointer, if such a node exists: or if not, an attempt is made to create one and return it.

pack-priv Object
Inherited from tools.jackson.databind.JsonNode:
_at_reportRequiredViolation_reportUnsupportedOperation_thisasOptionalasTextasTextatatcanConvertToExactIntegralcanConvertToIntcanConvertToLongcanConvertToShortdeepCopyequalsequalsfindParentfindParentsfindParentsfindValuefindValuesfindValuesfindValuesAsStringfindValuesAsStringforEachEntrygetgetgetNodeTypehashashasNonNullhasNonNullisArrayisBigDecimalisBigIntegerisBinaryisBooleanisContainerisDoubleisEmptyisFloatisFloatingPointNumberisIntisIntegralNumberisLongisNullisNumberisObjectisPojoisShortisStringisTextualisValueNodeiteratoroptionaloptionalpathpathpropertiespropertyNamespropertyStreamrequirerequiredAtrequiredAtrequireNonNullsizespliteratortextValuevaluesvalueStreamwithArraywithArraywithArraywithArrayPropertywithObjectwithObjectwithObjectwithObjectProperty