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
com..
Note that it is possible to "read" from nodes, using
method TreeNode#traverse(ObjectCodec), 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 extends JsonNode> T | |
| public boolean | |
| public boolean | asBoolean(boolean defaultValue)
Method that will try to convert value of this node to a Java boolean. |
| public double | |
| public double | |
| public int | |
| public int | |
| public long | |
| public long | |
| public abstract String | asText()
Method that will return a valid String representation of
the container value, if the node is a value node
(method |
| public String | |
| public final JsonNode | Returns: Node that matches given JSON Pointer: if no match exists, will return a node for whichisMissingNode() returns true.JsonPointer expression for descendant node to returnImplements com. 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 com. Convenience method that is functionally equivalent to: return at(JsonPointer.valueOf(jsonPointerExpression)); |
| public BigInteger | Returns: BigInteger value this node contains, if numeric node; BigInteger.ZERO for non-number nodes.Returns integer value for this node (as |
| public byte[] | Returns: Binary data this node contains, iff it is a binary node; null otherwiseMethod to use for accessing binary content of binary nodes (nodes
for which |
| public boolean | Returns: Boolean value this node contains, if any; otherwise alwaysfalseMethod to use for accessing JSON boolean values (value literals 'true' and 'false'). |
| 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 BigDecimal | Returns: BigDecimal value this node contains, if numeric node; BigDecimal.ZERO for non-number nodes.Returns floating point value for this node (as |
| public abstract <T extends JsonNode> T | 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 double | Returns: 64-bit double value this node contains, if any; 0.0 for non-number nodes.Returns 64-bit floating point (double) value for this node, if and only if
this node is numeric ( |
| public Iterator | elements()
Method for accessing all value nodes of this Node, iff this node is a JSON Array or Object node. |
| 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
the reference object with which to compare. o)Overrides java. Equality for node objects is defined as full (deep) value equality. |
| public Iterator | fieldNames()
Implements com. Method for accessing names of all fields for this node, if (and only if) this node is an Object node. |
| public Iterator | Returns: Iterator that can be used to traverse all key/value pairs for object nodes; empty iterator (no contents) for other types
|
| public abstract JsonNode | Returns: Value of first matching node found, if any; null if noneName of field to look for fieldName)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 fieldName)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 fieldName)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 | findValuesAsText(String fieldName)
Similar to |
| public abstract List | |
| public float | Returns: 32-bit float value this node contains, if any; 0.0 for non-number nodes.Returns 32-bit floating value for this node, if and only if
this node is numeric ( |
| public abstract JsonNode | Returns: Node that represent value of the specified element, if this node is an array and has specified element. Null otherwise.Index of the Array node element to access index)Redeclares com. 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.Name of the field (of Object node) to access fieldName)Implements com. 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 fieldName)
Method that is similar to |
| public boolean | hasNonNull(int index)
Method that is similar to |
| public int | |
| public boolean | isArray()
Implements com. 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 final boolean | isContainerNode()
Implements com. 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 com. 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 | |
| public final boolean | |
| public boolean | isObject()
Implements com. 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 final boolean | isValueNode()
Implements com. 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. Same as calling |
| public long | |
| public Number | Returns: Number value this node contains, if any (null for non-number nodes).Returns numeric value for this node, if and only if
this node is numeric ( |
| public abstract JsonNode | path(String
Name of the field (of Object node) to access fieldName)Redeclares com. This method is similar to |
| public abstract JsonNode | path(int
Index of the Array node element to access index)Redeclares com. 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 <T extends JsonNode> T | Returns: this node to allow chainingMethod that may be called to verify that |
| public JsonNode | Returns: Value of the specified property of this Object nodeName of property to access propertyName)Method is functionally equivalent to
|
| public 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 short | Returns: Short value this node contains, if any; 0 for non-number nodes.Returns 16-bit short value for this node, if and only if
this node is numeric ( |
| public int | size()
Implements com. Method that returns number of child nodes this node contains: for Array nodes, number of child elements, for Object nodes, number of fields, and for all other nodes 0. |
| public String | Returns: Textual value this node contains, iff it is a textual JSON node (comes from JSON String value entry)Method to use for accessing String values. |
| 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 <T extends JsonNode> T | with(String exprOrProperty)
Deprecated
Since 2.14 use
withObject(String) instead
Method that works in one of possible ways, depending on whether
|
| public <T extends JsonNode> T | Returns: ArrayNode found or createdEither exprOrProperty)JsonPointer expression for full access (if valid
pointer expression), or the name of property for the ArrayNode.Method that works in one of possible ways, depending on whether
|
| 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);
|