Interface JsonNode
- All Known Implementing Classes:
ArrayJsonNode,BooleanJsonNode,EmbeddedObjectJsonNode,NullJsonNode,NumberJsonNode,ObjectJsonNode,StringJsonNode
A node in a JSON document. Either a number, string, boolean, array, object or null. Also can be an embedded object,
which is a non-standard type used in JSON extensions, like CBOR.
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().
-
Method Summary
Modifier and TypeMethodDescriptionasArray()WhenisArray()is true, this returns the array associated with this node.booleanWhenisBoolean()is true, this returns the boolean associated with this node.WhenisEmbeddedObject()is true, this returns the embedded object associated with this node.asNumber()WhenisNumber()is true, this returns the number associated with this node.asObject()WhenisObject()is true, this returns the object associated with this node.asString()WhenisString(), is true, this returns the string associated with this node.static JsonNodeReturn an empty object node.WhenisObject()is true, this will return the result ofOptional.ofNullable(asObject().get(child)).index(int child) WhenisArray()is true, this will return the result ofasArray().get(child)if child is within bounds.default booleanisArray()Returns true if this node represents a JSON array: https://datatracker.ietf.org/doc/html/rfc8259#section-5default booleanReturns true if this node represents a JSON boolean: https://datatracker.ietf.org/doc/html/rfc8259#section-3default booleanReturns true if this node represents a JSON "embedded object".default booleanisNull()Returns true if this node represents a JSON null: https://datatracker.ietf.org/doc/html/rfc8259#section-3default booleanisNumber()Returns true if this node represents a JSON number: https://datatracker.ietf.org/doc/html/rfc8259#section-6default booleanisObject()Returns true if this node represents a JSON object: https://datatracker.ietf.org/doc/html/rfc8259#section-4default booleanisString()Returns true if this node represents a JSON string: https://datatracker.ietf.org/doc/html/rfc8259#section-7static JsonNodeParserparser()Create aJsonNodeParserfor generating aJsonNodefrom a JSON document.static JsonNodeParser.BuilderCreate aJsonNodeParser.Builderfor generating aJsonNodefrom a JSON document.text()WhenisString(),isBoolean(), orisNumber()is true, this will return the value of this node as a textual string.<T> Tvisit(JsonNodeVisitor<T> visitor) Visit this node using the provided visitor.
-
Method Details
-
parser
Create aJsonNodeParserfor generating aJsonNodefrom a JSON document. -
parserBuilder
Create aJsonNodeParser.Builderfor generating aJsonNodefrom a JSON document. -
emptyObjectNode
Return an empty object node. -
isNumber
default boolean isNumber()Returns true if this node represents a JSON number: https://datatracker.ietf.org/doc/html/rfc8259#section-6- See Also:
-
isString
default boolean isString()Returns true if this node represents a JSON string: https://datatracker.ietf.org/doc/html/rfc8259#section-7- See Also:
-
isBoolean
default boolean isBoolean()Returns true if this node represents a JSON boolean: https://datatracker.ietf.org/doc/html/rfc8259#section-3- See Also:
-
isNull
default boolean isNull()Returns true if this node represents a JSON null: https://datatracker.ietf.org/doc/html/rfc8259#section-3 -
isArray
default boolean isArray()Returns true if this node represents a JSON array: https://datatracker.ietf.org/doc/html/rfc8259#section-5- See Also:
-
isObject
default boolean isObject()Returns true if this node represents a JSON object: https://datatracker.ietf.org/doc/html/rfc8259#section-4- See Also:
-
isEmbeddedObject
default boolean isEmbeddedObject()Returns true if this node represents a JSON "embedded object". This non-standard type is associated with JSON extensions, like CBOR or ION. It allows additional data types to be embedded in a JSON document, like a timestamp or a raw byte array.Users who are only concerned with handling JSON can ignore this field. It will only be present when using a custom
JsonFactoryviaJsonNodeParser.Builder.jsonFactory(JsonFactory).- See Also:
-
asNumber
String asNumber()WhenisNumber()is true, this returns the number associated with this node. This will throw an exception ifisNumber()is false.- See Also:
-
asString
String asString()WhenisString(), is true, this returns the string associated with this node. This will throw an exception ifisString()()} is false. -
asBoolean
boolean asBoolean()WhenisBoolean()is true, this returns the boolean associated with this node. This will throw an exception ifisBoolean()is false. -
asArray
-
asObject
WhenisObject()is true, this returns the object associated with this node. This will throw an exception ifisObject()is false. -
asEmbeddedObject
Object asEmbeddedObject()WhenisEmbeddedObject()is true, this returns the embedded object associated with this node. This will throw an exception ifisEmbeddedObject()is false.- See Also:
-
visit
Visit this node using the provided visitor. -
text
String text()WhenisString(),isBoolean(), orisNumber()is true, this will return the value of this node as a textual string. If this is any other type, this will return null. -
field
WhenisObject()is true, this will return the result ofOptional.ofNullable(asObject().get(child)). If this is any other type, this will returnOptional.empty(). -
index
WhenisArray()is true, this will return the result ofasArray().get(child)if child is within bounds. If this is any other type or the child is out of bounds, this will returnOptional.empty().
-