Interface NodeAdapter

All Known Implementing Classes:
Jackson2Adapter, JakartaAdapter, NativeAdapter

public interface NodeAdapter
Provides a uniform abstraction for reading tree-like data structures.

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 Details

    • isNode

      boolean isNode(Object node)
      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

      Set<NodeType> nodeTypes()
      Returns the set of node types supported by this adapter.
      Returns:
      a set of supported node types
    • keyTypes

      Set<NodeType> 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

      NodeType type(Object node)
      Returns the type of the given node.
      Parameters:
      node - the node to inspect
      Returns:
      the NodeType of the node
    • isNull

      boolean isNull(Object node)
      Checks whether the node represents a null value.
      Parameters:
      node - the node to check
      Returns:
      true if the node is null, false otherwise
    • isBoolean

      boolean isBoolean(Object node)
      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

      boolean isBinary(Object node)
      Checks whether the node contains binary data.
      Parameters:
      node - the node to check
      Returns:
      true if the node is binary, false otherwise
    • size

      int size(Object node)
      Returns the number of entries in a map node or items in a collection node.

      Intended for nodes of type NodeType.MAP or NodeType.COLLECTION.

      Parameters:
      node - the node to inspect
      Returns:
      number of entries (for map) or items (for collection)
    • isEmpty

      boolean isEmpty(Object node)
      Checks whether a map node has no entries or a collection node has no items.

      This method is intended for nodes of type NodeType.MAP or NodeType.COLLECTION.

      Parameters:
      node - the node to inspect
      Returns:
      true if the map has no entries or the collection has no items, false otherwise
    • isMap

      boolean isMap(Object node)
      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

      Collection<?> keys(Object node)
      Returns the collection of property key nodes for a map node.
      Parameters:
      node - the map node
      Returns:
      collection of property key nodes
    • property

      Object property(Object key, Object node)
      Returns the property value associated with the specified key node in a map node.
      Parameters:
      key - the property key node
      node - the map node containing the property
      Returns:
      the property value node corresponding to the property key
    • entries

      Iterable<Map.Entry<?,?>> entries(Object node)
      Returns all key-value pairs of the given map node as an Iterable.
      Parameters:
      node - the map node
      Returns:
      iterable of key-value entries
    • entryStream

      Stream<Map.Entry<?,?>> entryStream(Object node)
      Returns all key-value pairs of the given map node as a Stream.
      Parameters:
      node - the map node
      Returns:
      stream of key-value entries
    • isCollection

      boolean isCollection(Object node)
      Checks whether the node represents a collection.
      Parameters:
      node - the node to check
      Returns:
      true if the node is a collection, false otherwise
    • isList

      boolean isList(Object node)
      Preserves insertion order and can contain duplicates.
      Parameters:
      node -
      Returns:
    • isSet

      boolean isSet(Object node)
      Contains only unique elements. Is unordered.
      Parameters:
      node -
      Returns:
    • elements

      Iterable<?> elements(Object node)
      Returns the child nodes of a collection node as an Iterable.
      Parameters:
      node - the collection node
      Returns:
      iterable of child nodes
    • elementStream

      Stream<?> elementStream(Object node)
      Returns the child nodes of a collection node as a Stream.
      Parameters:
      node - the collection node
      Returns:
      stream of child nodes
    • isString

      boolean isString(Object node)
      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

      String stringValue(Object node)
      Returns the string value of the node.
      Parameters:
      node - the string node
      Returns:
      string representation
    • isNumber

      boolean isNumber(Object node)
      Checks whether the node represents a numeric value.
      Parameters:
      node - the node to check
      Returns:
      true if the node is numeric, false otherwise
    • isIntegral

      boolean isIntegral(Object node)
      Checks whether a number node represents an integral value.

      Returns false for floating-point or BigDecimal nodes.

      Parameters:
      node - the number node
      Returns:
      true if the node is integral, false otherwise
    • intValue

      int intValue(Object node)
      Returns the integer value of a number node.
      Parameters:
      node - the number node
      Returns:
      integer value
    • longValue

      long longValue(Object node)
      Returns the long value of a number node.
      Parameters:
      node - the number node
      Returns:
      long value
    • bigIntegerValue

      BigInteger bigIntegerValue(Object node)
      Returns the BigInteger value of a number node.
      Parameters:
      node - the number node
      Returns:
      BigInteger value
    • doubleValue

      double doubleValue(Object node)
      Returns the double value of a number node.
      Parameters:
      node - the number node
      Returns:
      double value
    • decimalValue

      BigDecimal decimalValue(Object node)
      Returns the BigDecimal value of a number node.
      Parameters:
      node - the number node
      Returns:
      BigDecimal value
    • binaryValue

      byte[] binaryValue(Object node)
      Returns the binary value of the node as a byte array.
      Parameters:
      node - the binary node
      Returns:
      byte array representation
    • asIterable

      Iterable<?> asIterable(Object node)
      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

      Stream<?> asStream(Object node)
      Returns the node as a stream.
      Parameters:
      node - the node to convert
      Returns:
      stream of elements
    • asString

      String asString(Object node)
      Returns the string representation of the node, converting other types as needed.
      Parameters:
      node - the node to convert
      Returns:
      string representation
    • asDecimal

      BigDecimal asDecimal(Object node)
      Converts the given node to a BigDecimal, if possible.
      Parameters:
      node - the node to convert
      Returns:
      BigDecimal representation of the node