Interface JsonDocument

All Known Subinterfaces:
JsonArray, JsonObject, JsonSchema
All Known Implementing Classes:
Args

public interface JsonDocument
An encoded JSON value.

The server validates and parses the JSON when it crosses a runtime boundary. Implementations may retain a stable provider-specific representation and expose it through unwrap(Class). The encoded and retained representations must describe the same value.

Author:
Konstantin Pavlov
  • Method Details

    • json

      String json()
      Returns the encoded JSON value.
      Returns:
      the JSON string
    • unwrap

      @ExperimentalApi default <T> Optional<T> unwrap(Class<T> type)
      Returns the retained provider-specific representation when it matches type.

      The default implementation is provider-neutral and returns an empty optional.

      Type Parameters:
      T - the requested representation type
      Parameters:
      type - the class of the requested representation
      Returns:
      the provider-specific representation, or empty if not available
    • of

      static JsonDocument of(String json)
      Creates a document from encoded JSON.
      Parameters:
      json - the JSON string
      Returns:
      a new document
    • parse

      static JsonDocument parse(String json)
      Creates a document from encoded JSON, validating it via the JsonDocumentFactory discovered through ServiceLoader for String.
      Parameters:
      json - the JSON string
      Returns:
      the parsed document
      Throws:
      IllegalArgumentException - if json is not valid JSON
      IllegalStateException - if no JsonDocumentFactory<String> is registered
    • from

      static <T> JsonDocument from(T source, Class<T> type)
      Creates a document from an already-parsed representation, via the JsonDocumentFactory discovered through ServiceLoader for type.
      Type Parameters:
      T - the source representation type
      Parameters:
      source - the source representation, e.g. a Jackson JsonNode
      type - the source representation's type
      Returns:
      the parsed document
      Throws:
      IllegalStateException - if no JsonDocumentFactory<T> is registered for type