Interface NodeAdapter
- All Known Implementing Classes:
Jackson2Adapter,JakartaAdapter,NativeAdapter
Implementations can support any tree representation (JSON, YAML, CBOR, etc.) and any underlying library (Jackson, Gson, Jakarta, etc.).
Each adapter may support only a subset of nodes from a representation.
Methods may throw IllegalArgumentException,
ClassCastException, NullPointerException, or
IllegalStateException if a node cannot be processed or an operation
fails.
-
Method Summary
Modifier and TypeMethodDescriptionConverts the given node to aBigDecimal, if possible.Iterable<?>asIterable(Object node) Returns the node as an iterable.Stream<?>Returns the node as a stream.Returns the string representation of the node, converting other types as needed.bigIntegerValue(Object node) Returns theBigIntegervalue of a number node.byte[]binaryValue(Object node) Returns the binary value of the node as a byte array.decimalValue(Object node) Returns theBigDecimalvalue of a number node.doubledoubleValue(Object node) Returns the double value of a number node.Iterable<?>Returns the child nodes of a collection node as anIterable.Stream<?>elementStream(Object node) Returns the child nodes of a collection node as aStream.Returns all key-value pairs of the given map node as anIterable.entryStream(Object node) Returns all key-value pairs of the given map node as aStream.intReturns the integer value of a number node.booleanChecks whether the node contains binary data.booleanChecks whether the node represents a boolean value.booleanisCollection(Object node) Checks whether the node represents a collection.booleanChecks whether a map node has no entries or a collection node has no items.booleanisIntegral(Object node) Checks whether a number node represents an integral value.booleanPreserves insertion order and can contain duplicates.booleanChecks whether the node represents a map (object) structure.booleanChecks whether the given object can be processed by this adapter.booleanChecks whether the node represents a null value.booleanChecks whether the node represents a numeric value.booleanContains only unique elements.booleanChecks whether the node represents a string value.Collection<?>Returns the collection of property key nodes for a map node.keyTypes()Returns the set of node types that are supported as keys in map nodes for this adapter.longReturns the long value of a number node.Returns the set of node types supported by this adapter.Returns the property value associated with the specified key node in a map node.intReturns the number of entries in a map node or items in a collection node.stringValue(Object node) Returns the string value of the node.Returns the type of the given node.
-
Method Details
-
isNode
Checks whether the given object can be processed by this adapter.Returns true if the adapter is capable of handling the node type; false otherwise.
- Parameters:
node- the object to check- Returns:
- true if the node can be adapted by this adapter, false otherwise
-
nodeTypes
Returns the set of node types supported by this adapter.- Returns:
- a set of supported node types
-
keyTypes
Returns the set of node types that are supported as keys in map nodes for this adapter.- Returns:
- a set of supported key node types
-
type
Returns the type of the given node.- Parameters:
node- the node to inspect- Returns:
- the
NodeTypeof the node
-
isNull
Checks whether the node represents a null value.- Parameters:
node- the node to check- Returns:
- true if the node is null, false otherwise
-
isBoolean
Checks whether the node represents a boolean value.- Parameters:
node- the node to check- Returns:
- true if the node is a boolean, false otherwise
-
isBinary
Checks whether the node contains binary data.- Parameters:
node- the node to check- Returns:
- true if the node is binary, false otherwise
-
size
Returns the number of entries in a map node or items in a collection node.Intended for nodes of type
NodeType.MAPorNodeType.COLLECTION.- Parameters:
node- the node to inspect- Returns:
- number of entries (for map) or items (for collection)
-
isEmpty
Checks whether a map node has no entries or a collection node has no items.This method is intended for nodes of type
NodeType.MAPorNodeType.COLLECTION.- Parameters:
node- the node to inspect- Returns:
- true if the map has no entries or the collection has no items, false otherwise
-
isMap
Checks whether the node represents a map (object) structure.- Parameters:
node- the node to check- Returns:
- true if the node is a map, false otherwise
-
keys
Returns the collection of property key nodes for a map node.- Parameters:
node- the map node- Returns:
- collection of property key nodes
-
property
Returns the property value associated with the specified key node in a map node.- Parameters:
key- the property key nodenode- the map node containing the property- Returns:
- the property value node corresponding to the property key
-
entries
Returns all key-value pairs of the given map node as anIterable.- Parameters:
node- the map node- Returns:
- iterable of key-value entries
-
entryStream
Returns all key-value pairs of the given map node as aStream.- Parameters:
node- the map node- Returns:
- stream of key-value entries
-
isCollection
Checks whether the node represents a collection.- Parameters:
node- the node to check- Returns:
- true if the node is a collection, false otherwise
-
isList
Preserves insertion order and can contain duplicates.- Parameters:
node-- Returns:
-
isSet
Contains only unique elements. Is unordered.- Parameters:
node-- Returns:
-
elements
Returns the child nodes of a collection node as anIterable.- Parameters:
node- the collection node- Returns:
- iterable of child nodes
-
elementStream
Returns the child nodes of a collection node as aStream.- Parameters:
node- the collection node- Returns:
- stream of child nodes
-
isString
Checks whether the node represents a string value.- Parameters:
node- the node to check- Returns:
- true if the node is a string, false otherwise
-
stringValue
Returns the string value of the node.- Parameters:
node- the string node- Returns:
- string representation
-
isNumber
Checks whether the node represents a numeric value.- Parameters:
node- the node to check- Returns:
- true if the node is numeric, false otherwise
-
isIntegral
Checks whether a number node represents an integral value.Returns false for floating-point or
BigDecimalnodes.- Parameters:
node- the number node- Returns:
- true if the node is integral, false otherwise
-
intValue
Returns the integer value of a number node.- Parameters:
node- the number node- Returns:
- integer value
-
longValue
Returns the long value of a number node.- Parameters:
node- the number node- Returns:
- long value
-
bigIntegerValue
Returns theBigIntegervalue of a number node.- Parameters:
node- the number node- Returns:
- BigInteger value
-
doubleValue
Returns the double value of a number node.- Parameters:
node- the number node- Returns:
- double value
-
decimalValue
Returns theBigDecimalvalue of a number node.- Parameters:
node- the number node- Returns:
- BigDecimal value
-
binaryValue
Returns the binary value of the node as a byte array.- Parameters:
node- the binary node- Returns:
- byte array representation
-
asIterable
Returns the node as an iterable.If the node is null, returns an empty iterable. If it is a single element, wraps it as a singleton iterable. Useful for iterating without type checks.
- Parameters:
node- the node to convert- Returns:
- iterable of elements
-
asStream
Returns the node as a stream.- Parameters:
node- the node to convert- Returns:
- stream of elements
-
asString
Returns the string representation of the node, converting other types as needed.- Parameters:
node- the node to convert- Returns:
- string representation
-
asDecimal
Converts the given node to aBigDecimal, if possible.- Parameters:
node- the node to convert- Returns:
- BigDecimal representation of the node
-