As a general design rule, most accessors ("getters") are included
in this base class, to allow for traversing structure without
type casts. Most mutators, however, need to be accessed through
specific sub-classes (such as ObjectNode
and ArrayNode).
This seems sensible because proper type
information is generally available when building or modifying
trees, but less often when reading a tree (newly built from
parsed JSON content).
Actual concrete sub-classes can be found from package
tools..
Note that it is possible to "read" from nodes, using
method TreeNode#traverse, which will result in
a JsonParser being constructed. This can be used for (relatively)
efficient conversations between different representations; and it is what
core databind uses for methods like ObjectMapper#treeToValue(TreeNode, Class)
and ObjectMapper#treeAsTokens(TreeNode)
| Modifier and Type | Class and Description |
|---|---|
| public static enum | JsonNode.
Configuration setting used with |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| protected abstract JsonNode | Returns: Either matchingJsonNode for the first step of path or
null if no match (including case that this node is not a container)Path expression to use ptr)Helper method used by other methods for traversing the next step
of given path expression, and returning matching value node if any:
if no match, |
| protected <T> T | _reportRequiredViolation(String msgTemplate, Object... args)
Helper method that throws |
| protected <T> T | |
| protected <T extends JsonNode> T | |
| public abstract BigInteger | Returns: BigInteger value this node represents, if possible to accurately convert;
defaultValue otherwiseMethod similar to
|
| public abstract BigInteger | Returns: BigInteger value this node represents, if possible to accurately convert;
defaultValue otherwiseValue to return if this node cannot be converted to defaultValue)BigIntegerMethod similar to |
| public abstract Optional | Returns: BigInteger value this node represents, as Optional<BigInteger>,
if possible to accurately represent; Optional.empty() otherwise.Method similar to |
| public abstract boolean | Returns: Boolean value this node represents, if coercible; exception otherwiseMethod that will try to convert value of this node to a Java |
| public abstract boolean | asBoolean(boolean defaultValue)
Similar to |
| public abstract Optional | asBooleanOpt()
Similar to |
| public abstract BigDecimal | Returns: BigDecimal value this node represents, if possible to accurately representMethod that will try to access value of this node as a |
| public abstract BigDecimal | Returns: BigDecimal value this node represents,
if possible to accurately represent; defaultValue otherwiseMethod similar to |
| public abstract Optional | Returns: JavaBigDecimal value this node represents, as Optional<BigDecimal>,
if possible to accurately represent; Optional.empty() otherwiseMethod similar to |
| public abstract double | Returns: double value this node represents, if possible to accurately representMethod similar to
|
| public abstract double | Returns: double value this node represents,
if possible to accurately represent; defaultValue otherwiseMethod similar to |
| public abstract OptionalDouble | Returns: OptionalDouble value this node represents,
if possible to accurately represent; OptionalDouble.empty() otherwiseMethod similar to |
| public abstract float | Returns: float value this node represents, if possible to accurately representMethod similar to
|
| public abstract float | |
| public abstract Optional | Returns: Optional<Float> value this node represents,
if possible to accurately represent; Optional.empty() otherwiseMethod similar to |
| public abstract int | Returns: int value this node represents, if possible to accurately representMethod similar to
|
| public abstract int | Returns: int value this node represents, if possible to accurately represent;
defaultValue otherwiseValue to return if this node cannot be converted to defaultValue)intMethod similar to |
| public abstract OptionalInt | Returns: OptionalInt value this node represents,
if possible to accurately represent; OptionalInt.empty() otherwiseMethod similar to |
| public abstract long | Returns: long value this node represents, if possible to accurately representMethod similar to
|
| public abstract long | Returns: long value this node represents, if possible to accurately represent;
defaultValue otherwiseValue to return if this node cannot be coerced to defaultValue)longMethod similar to |
| public abstract OptionalLong | Returns: OptionalLong value this node represents (or can be coerced to),
OptionalLong.empty() otherwiseMethod similar to |
| public Optional | |
| public abstract short | Returns: short value this node represents, if possible to accurately representMethod similar to
|
| public abstract short | Returns: short value this node represents, if possible to accurately represent;
defaultValue otherwiseValue to return if this node cannot be converted to defaultValue)shortMethod similar to |
| public abstract Optional | Returns: Optional<Short> value this node represents,
if possible to accurately represent; Optional.empty() otherwiseMethod similar to |
| public abstract String | Returns: String representation of this node, if coercible; exception otherwiseMethod that will try to convert value of this node to a |
| public abstract String | asString(String defaultValue)
Similar to |
| public abstract Optional | asStringOpt()
Similar to |
| public final String | |
| public String | |
| public final JsonNode | Returns: Node that matches given JSON Pointer: if no match exists, will return a node for whichisMissingNode() returns true.Implements tools. Method for locating node specified by given JSON pointer instances. |
| public final JsonNode | Returns: Node that matches given JSON Pointer: if no match exists, will return a node for whichTreeNode#isMissingNode() returns true.Expression to compile as a jsonPtrExpr)JsonPointer
instanceImplements tools. Convenience method that is functionally equivalent to: return at(JsonPointer.valueOf(jsonPointerExpression)); |
| public abstract BigInteger | Returns: BigInteger value this node represents, if possible to accurately representMethod that will try to access value of this node as a |
| public abstract BigInteger | Returns: JavaBigInteger value this node represents, if possible to accurately represent;
defaultValue otherwiseValue to return if this node cannot be converted to Java defaultValue)BigIntegerMethod similar to |
| public abstract Optional | Returns: JavaBigInteger value this node represents, as Optional<BigInteger>,
if possible to accurately represent; Optional.empty() otherwiseMethod similar to |
| public abstract byte[] | Returns: Binary value this node represents (if node contains binary value)Method that will try to access value of this node as binary value (Java |
| public abstract boolean | Returns: boolean value this node represents (if JSON boolean)Method that will try to access value of this node as a Java |
| public abstract boolean | Returns: Javaboolean value this node represents (if JSON boolean);
defaultValue otherwiseValue to return if this node does not contain a JSON boolean. defaultValue)Method similar to |
| public abstract Optional | Returns: Optional<Boolean> value (if node represents JSON boolean);
Optional.empty() otherwiseMethod similar to |
| public boolean | Returns: True if the value is an actual number with no fractional part; false for non-numeric types, NaN representations of floating-point numbers, and floating-point numbers with fractional part.Method that can be used to check whether contained value
is numeric (returns true for |
| public boolean | canConvertToInt()
Method that can be used to check whether this node is a numeric
node ( |
| public boolean | canConvertToLong()
Method that can be used to check whether this node is a numeric
node ( |
| public boolean | canConvertToShort()
Method that can be used to check whether this node is a numeric
node ( |
| public abstract BigDecimal | Returns: BigDecimal value this node represents, if possible to accurately representMethod that will try to access value of this node as a Java |
| public abstract BigDecimal | Returns: BigDecimal value this node represents,
if possible to accurately represent; defaultValue otherwiseMethod similar to |
| public abstract Optional | Returns: JavaBigDecimal value this node represents, as Optional<BigDecimal>,
if possible to accurately represent; Optional.empty() otherwiseMethod similar to |
| public abstract JsonNode | Returns: Node that is either a copy of this node (and all non-leaf children); or, for immutable leaf nodes, node itself.Method that can be called to get a node that is guaranteed not to allow changing of this node through mutators on this node or any of its children. |
| public abstract double | Returns: Double value this node represents, if possible to accurately representMethod that will try to access value of this node as a |
| public abstract double | Returns: double value this node represents, if possible to accurately represent;
defaultValue otherwiseValue to return if this node cannot be converted to defaultValue)doubleMethod similar to |
| public abstract OptionalDouble | Returns: Javadouble value this node represents, as OptionalDouble,
if possible to accurately represent; OptionalDouble.empty() otherwiseMethod similar to |
| public boolean | equals(Comparator<JsonNode>
Object called to compare two scalar comparator, JsonNode other)JsonNode
instances, and return either 0 (are equals) or non-zero (not equal)Entry method for invoking customizable comparison, using passed-in
|
| public abstract boolean | equals(Object o)
Overrides java. Equality for node objects is defined as full (deep) value equality. |
| public abstract JsonNode | Returns: Value of first matching node found, if any; null if noneName of field to look for propertyName)Method for finding a JSON Object that contains specified field, within this node or its descendants. |
| public final List | Returns: Value of first matching node found, if any; null if noneName of field to look for propertyName)Method for finding a JSON Object that contains specified field, within this node or its descendants. |
| public abstract List | |
| public abstract JsonNode | |
| public abstract JsonNode | |
| public final List | findValues(String
Name of field to look for propertyName)Method for finding JSON Object fields with specified name -- both immediate
child values and descendants -- and returning
found ones as a |
| public abstract List | |
| public final List | findValuesAsString(String propertyName)
Similar to |
| public abstract List | |
| public abstract float | Returns: Float value this node represents, if possible to accurately representMethod that will try to access value of this node as a Java |
| public abstract float | Returns: float value this node represents, if possible to accurately represent;
defaultValue otherwiseValue to return if this node cannot be converted to defaultValue)floatMethod similar to |
| public abstract Optional | Returns: Javafloat value this node represents, as Optional<Float>,
if possible to accurately represent; Optional.empty() otherwiseMethod similar to |
| public void | forEachEntry(BiConsumer<? super String, ? super JsonNode>
Action to perform for each entry action)If this node is an |
| public abstract JsonNode | Returns: Node that represent value of the specified element, if this node is an array and has specified element. Null otherwise.Redeclares tools. Method for accessing value of the specified element of an array node. |
| public JsonNode | Returns: Node that represent value of the specified field, if this node is an object and has value for the specified field. Null otherwise.Implements tools. Method for accessing value of the specified field of an object node. |
| public abstract JsonNodeType | |
| public boolean | |
| public boolean | Returns: True if this node is a JSON Object node, and has a property entry with specified name (with any value, including null value)Index to check index)Method that allows checking whether this node is JSON Array node and contains a value for specified index If this is the case (including case of specified indexing having null as value), returns true; otherwise returns false. |
| public boolean | hasNonNull(String propertyName)
Method that is similar to |
| public boolean | hasNonNull(int index)
Method that is similar to |
| public abstract int | Returns: Int value this node represents, if possible to accurately representMethod that will try to access value of this node as a Java |
| public abstract int | Returns: Javaint value this node represents, if possible to accurately represent;
defaultValue otherwiseValue to return if this node cannot be converted to Java defaultValue)intMethod similar to |
| public abstract OptionalInt | Returns: Javaint value this node represents, as OptionalInt,
if possible to accurately represent; OptionalInt.empty() otherwiseMethod similar to |
| public boolean | isArray()
Implements tools. Method that returns true if this node is an Array node, false otherwise. |
| public boolean | |
| public boolean | |
| public final boolean | Returns: True if this node represents base64 encoded binary dataMethod that can be used to check if this node represents binary data (Base64 encoded). |
| public final boolean | isBoolean()
Method that can be used to check if this node was created from JSON boolean value (literals "true" and "false"). |
| public boolean | isContainer()
Implements tools. Method that returns true for container nodes: Arrays and Objects. |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | Returns: True if the value contained by this node is stored as Java intMethod that can be used to check whether contained value
is a number represented as Java |
| public boolean | |
| public boolean | Returns: True if the value contained by this node is stored as JavalongMethod that can be used to check whether contained value
is a number represented as Java |
| public boolean | isMissingNode()
Implements tools. 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 final boolean | isNull()
Implements tools. Method that can be used to check if this node was created from JSON literal null value. |
| public final boolean | |
| public boolean | isObject()
Implements tools. Method that returns true if this node is an Object node, false otherwise. |
| public final boolean | Returns: True if this node wraps a POJOMethod that can be used to check if the node is a wrapper for a POJO ("Plain Old Java Object" aka "bean". |
| public boolean | Returns: True if the value contained by this node is stored as Java shortMethod that can be used to check whether contained value
is a number represented as Java |
| public final boolean | |
| public boolean | |
| public final boolean | isValueNode()
Implements tools. Method that returns true for all value nodes: ones that are not containers, and that do not represent "missing" nodes in the path. |
| public final Iterator | iterator()
Implements java. Implemented so that convenience "for-each" loop can be used for looping over elements of JSON Array constructs. |
| public abstract long | Returns: Long value this node represents, if possible to accurately representMethod that will try to access value of this node as a Java |
| public abstract long | Returns: long value this node represents, if possible to accurately represent;
defaultValue otherwiseValue to return if this node cannot be converted to defaultValue)longMethod similar to |
| public abstract OptionalLong | Returns: Javalong value this node represents, as OptionalLong,
if possible to accurately represent; OptionalLong.empty() otherwiseMethod similar to |
| public abstract Number | Returns: Number value this node contains, if numeric nodeMethod that will try to access value of this node as |
| public Optional | Returns: Optional containing the node that represents the value of the specified element, if this node is an array and has the specified element and otherwise, an empty Optional, never null.Method for accessing value of the specified element of
an array node, wrapped in an |
| public Optional | |
| public abstract JsonNode | path(String propertyName)
Redeclares tools. This method is similar to |
| public abstract JsonNode | path(int index)
Redeclares tools. This method is similar to |
| public Set | Returns: Set of properties, if this node is anObjectNode
(JsonNode#isObject() returns true); empty
java. otherwise.Accessor that will return properties of |
| public Collection | propertyNames()
Implements tools. Method for accessing names of all properties for this node, if (and only if) this node is an Object node. |
| public Stream | propertyStream()
Returns a stream of all properties (key, value pairs) of this Node,
iff this node is an an |
| public <T extends JsonNode> T | Returns: this node to allow chainingMethod that may be called to verify that |
| public abstract JsonNode | Returns: Value of the specified property of this Object nodeName of property to access propertyName)Method is functionally equivalent to
|
| public abstract JsonNode | Returns: Value at specified index of this Array nodeIndex of the value of this Array node to access index)Method is functionally equivalent to
|
| public JsonNode | Returns: Matching value node for given expressionJsonPointer expression (as String) to use for finding value nodeMethod is functionally equivalent to
|
| public final JsonNode | Returns: Matching value node for given expressionJsonPointer expression to use for finding value nodeMethod is functionally equivalent to
|
| public <T extends JsonNode> T | Returns: this node to allow chainingMethod that may be called to verify that |
| public abstract short | Returns: Short value this node represents, if possible to accurately representMethod that will try to access value of this node as 16-bit signed
integer value (Java |
| public abstract short | Returns: Javashort value this node represents, if possible to accurately represent;
defaultValue otherwiseValue to return if this node cannot be converted to Java defaultValue)shortMethod similar to |
| public abstract Optional | Returns: Javashort value this node represents, as Optional<Short>,
if possible to accurately represent; Optional.empty() otherwiseMethod similar to |
| public int | size()
Implements tools. Method that returns number of child nodes this node contains: for Array nodes, number of child elements, for Object nodes, number of properties, and for all other nodes 0. |
| public final Spliterator | spliterator()
Overrides default java. Creates a |
| public abstract String | Returns: String value this node represents (if JSON String),
null for JSON nullMethod that will try to access value of this node as a Java |
| public abstract String | Returns: JavaString value this node represents (if JSON String);
defaultValue otherwise -- only returns null if defaultValue
is nullValue to return if this node does not contain a JSON String. defaultValue)Method similar to |
| public abstract Optional | Returns: Optional<String> value (if node represents JSON String);
Optional.empty() otherwise (including for JSON null)Method similar to |
| public final String | |
| public String | toPrettyString()
Alternative to |
| public abstract String | toString()
Overrides java. Method that will produce (as of Jackson 2.10) valid JSON using default settings of databind, as String. |
| public Collection | values()
Method for accessing all value nodes of this Node, iff this node is a JSON Array or Object node. |
| public Stream | valueStream()
Returns a stream of all value nodes of this Node, iff
this node is an |
| public ArrayNode | |
| public ArrayNode | withArray(String expr, JsonNode.
Short-cut equivalent to: withArray(JsonPointer.compile(expr), overwriteMode, preferIndex); |
| public final ArrayNode | Returns: ArrayNode found or createdPointer that indicates path to use for ptr)ArrayNode to return
(potentially creating as necessary)Same as |
| public ArrayNode | Returns: ArrayNode found or createdPointer that indicates path to use for ptr, JsonNode.ArrayNode value to return
(potentially creating it as necessary)Defines which node types may be converted in case of
incompatible overwriteMode,JsonPointer expression: if conversion not allowed,
an exception is thrown.When creating a path (for empty or replacement), and path
contains segment that may be an array index (simple integer number like
preferIndex)3), whether to construct an ArrayNode (true) or
ObjectNode (false). In latter case matching property with
quoted number (like "3") is used within Object.Method that can be called on Object or Array nodes, to access a Array-valued
node pointed to by given |
| public ArrayNode | Returns: ArrayNode value of given property (existing or created)Name of property that has or will have propName)ArrayNode as valueMethod similar to
withArray(JsonPointer.compile("/"+propName), OverwriteMode.NULLS, false);
|
| public ObjectNode | Returns: ObjectNode found or createdJsonPointer expression to use (if valid as one),
or, if not (no leading "/"), property name to match.Method that works in one of possible ways, depending on whether
|
| public final ObjectNode | withObject(String expr, JsonNode.
Short-cut equivalent to: withObject(JsonPointer.compile(expr), overwriteMode, preferIndex); |
| public final ObjectNode | Returns: ObjectNode found or createdJsonPointer that indicates path to use for Object value to return
(potentially creating as necessary)Same as |
| public ObjectNode | Returns: ObjectNode found or createdPointer that indicates path to use for ptr, JsonNode.ObjectNode value to return
(potentially creating one as necessary)Defines which node types may be converted in case of
incompatible overwriteMode,JsonPointer expression: if conversion not allowed,
UnsupportedOperationException is thrown.When creating a path (for empty or replacement), and path
contains segment that may be an array index (simple integer number like
preferIndex)3), whether to construct an ArrayNode (true) or
ObjectNode (false). In latter case matching property with
quoted number (like "3") is used within Object.Method that can be called on Object or Array nodes, to access a Object-valued
node pointed to by given |
| public ObjectNode | Returns: ObjectNode value of given property (existing or created)Name of property that has or will have propName)ObjectNode as valueMethod similar to
withObject(JsonPointer.compile("/"+propName), OverwriteMode.NULLS, false);
|