Package dev.tachyonmcp.api.json
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 Summary
Modifier and TypeMethodDescriptionstatic <T> JsonDocumentCreates a document from an already-parsed representation, via theJsonDocumentFactorydiscovered throughServiceLoaderfortype.json()Returns the encoded JSON value.static JsonDocumentCreates a document from encoded JSON.static JsonDocumentCreates a document from encoded JSON, validating it via theJsonDocumentFactorydiscovered throughServiceLoaderforString.default <T> Optional<T> Returns the retained provider-specific representation when it matchestype.
-
Method Details
-
json
String json()Returns the encoded JSON value.- Returns:
- the JSON string
-
unwrap
Returns the retained provider-specific representation when it matchestype.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
Creates a document from encoded JSON.- Parameters:
json- the JSON string- Returns:
- a new document
-
parse
Creates a document from encoded JSON, validating it via theJsonDocumentFactorydiscovered throughServiceLoaderforString.- Parameters:
json- the JSON string- Returns:
- the parsed document
- Throws:
IllegalArgumentException- ifjsonis not valid JSONIllegalStateException- if noJsonDocumentFactory<String>is registered
-
from
Creates a document from an already-parsed representation, via theJsonDocumentFactorydiscovered throughServiceLoaderfortype.- Type Parameters:
T- the source representation type- Parameters:
source- the source representation, e.g. a JacksonJsonNodetype- the source representation's type- Returns:
- the parsed document
- Throws:
IllegalStateException- if noJsonDocumentFactory<T>is registered fortype
-