public interface JsonNode
Created from a JSON document via parser()
or parserBuilder()
.
The type of node can be determined using "is" methods like isNumber()
and isString()
.
Once the type is determined, the value of the node can be extracted via the "as" methods, like asNumber()
and asString()
.
Modifier and Type | Method and Description |
---|---|
List<JsonNode> |
asArray()
When
isArray() is true, this returns the array associated with this node. |
boolean |
asBoolean()
When
isBoolean() is true, this returns the boolean associated with this node. |
Object |
asEmbeddedObject()
When
isEmbeddedObject() is true, this returns the embedded object associated with this node. |
String |
asNumber()
When
isNumber() is true, this returns the number associated with this node. |
Map<String,JsonNode> |
asObject()
When
isObject() is true, this returns the object associated with this node. |
String |
asString()
When
isString() , is true, this returns the string associated with this node. |
static JsonNode |
emptyObjectNode()
Return an empty object node.
|
default Optional<JsonNode> |
field(String child)
When
isObject() is true, this will return the result of Optional.ofNullable(asObject().get(child)) . |
default Optional<JsonNode> |
index(int child)
When
isArray() is true, this will return the result of asArray().get(child) if child is within bounds. |
default boolean |
isArray()
Returns true if this node represents a JSON array: https://datatracker.ietf.org/doc/html/rfc8259#section-5
|
default boolean |
isBoolean()
Returns true if this node represents a JSON boolean: https://datatracker.ietf.org/doc/html/rfc8259#section-3
|
default boolean |
isEmbeddedObject()
Returns true if this node represents a JSON "embedded object".
|
default boolean |
isNull()
Returns true if this node represents a JSON null: https://datatracker.ietf.org/doc/html/rfc8259#section-3
|
default boolean |
isNumber()
Returns true if this node represents a JSON number: https://datatracker.ietf.org/doc/html/rfc8259#section-6
|
default boolean |
isObject()
Returns true if this node represents a JSON object: https://datatracker.ietf.org/doc/html/rfc8259#section-4
|
default boolean |
isString()
Returns true if this node represents a JSON string: https://datatracker.ietf.org/doc/html/rfc8259#section-7
|
static JsonNodeParser |
parser()
Create a
JsonNodeParser for generating a JsonNode from a JSON document. |
static JsonNodeParser.Builder |
parserBuilder()
Create a
JsonNodeParser.Builder for generating a JsonNode from a JSON document. |
String |
text()
When
isString() , isBoolean() , or isNumber() is true, this will return the value of this node
as a textual string. |
<T> T |
visit(JsonNodeVisitor<T> visitor)
Visit this node using the provided visitor.
|
static JsonNodeParser parser()
JsonNodeParser
for generating a JsonNode
from a JSON document.static JsonNodeParser.Builder parserBuilder()
JsonNodeParser.Builder
for generating a JsonNode
from a JSON document.static JsonNode emptyObjectNode()
default boolean isNumber()
asNumber()
default boolean isString()
asString()
default boolean isBoolean()
asBoolean()
default boolean isNull()
default boolean isArray()
asArray()
default boolean isObject()
asObject()
default boolean isEmbeddedObject()
Users who are only concerned with handling JSON can ignore this field. It will only be present when using a custom
JsonFactory
via JsonNodeParser.Builder.jsonFactory(JsonFactory)
.
asEmbeddedObject()
String asNumber()
isNumber()
is true, this returns the number associated with this node. This will throw an exception if
isNumber()
is false.text()
String asString()
isString()
, is true, this returns the string associated with this node. This will throw an exception if
isString()
()} is false.boolean asBoolean()
isBoolean()
is true, this returns the boolean associated with this node. This will throw an exception if
isBoolean()
is false.Map<String,JsonNode> asObject()
isObject()
is true, this returns the object associated with this node. This will throw an exception if
isObject()
is false.Object asEmbeddedObject()
isEmbeddedObject()
is true, this returns the embedded object associated with this node. This will throw
an exception if isEmbeddedObject()
is false.isEmbeddedObject()
<T> T visit(JsonNodeVisitor<T> visitor)
String text()
isString()
, isBoolean()
, or isNumber()
is true, this will return the value of this node
as a textual string. If this is any other type, this will return null.default Optional<JsonNode> field(String child)
isObject()
is true, this will return the result of Optional.ofNullable(asObject().get(child))
. If
this is any other type, this will return Optional.empty()
.default Optional<JsonNode> index(int child)
isArray()
is true, this will return the result of asArray().get(child)
if child is within bounds. If
this is any other type or the child is out of bounds, this will return Optional.empty()
.Copyright © 2023. All rights reserved.