Class Args

java.lang.Object
dev.tachyonmcp.api.server.domain.Args
All Implemented Interfaces:
JsonDocument, JsonObject

public final class Args extends Object implements JsonObject
Arguments container wrapping a JsonObject with optional deserialization support.
  • Method Details

    • of

      public static Args of(@Nullable Map<String,?> values)
      Creates arguments from a map of values.
      Parameters:
      values - the argument values, or null for empty
      Returns:
      a new Args instance
    • empty

      public static Args empty()
      Returns a shared empty arguments instance.
      Returns:
      empty args
    • of

      public static Args of(@Nullable Map<String,?> values, @Nullable PayloadDeserializer deserializer)
      Creates arguments from a map of values with a deserializer.
      Parameters:
      values - the argument values, or null for empty
      deserializer - the payload deserializer, or null
      Returns:
      a new Args instance
    • from

      public static Args from(JsonObject values, @Nullable PayloadDeserializer deserializer)
      Creates arguments from a JSON object with a deserializer.
      Parameters:
      values - the JSON object containing argument values
      deserializer - the payload deserializer, or null
      Returns:
      a new Args instance
    • isEmpty

      public boolean isEmpty()
      Returns whether the arguments are empty.
      Returns:
      true if no arguments are present
    • has

      public boolean has(String name)
      Description copied from interface: JsonObject
      Returns whether the object has property name, including when its value is JSON null.
      Specified by:
      has in interface JsonObject
      Parameters:
      name - the property name
      Returns:
      true if the property exists
    • objectOpt

      public Optional<JsonObject> objectOpt(String name)
      Description copied from interface: JsonObject
      Returns the named object, or an empty optional when it is missing or JSON null.
      Specified by:
      objectOpt in interface JsonObject
      Parameters:
      name - the property name
      Returns:
      the object value, or empty if missing or null
    • arrayOpt

      public Optional<JsonArray> arrayOpt(String name)
      Description copied from interface: JsonObject
      Returns the named array, or an empty optional when it is missing or JSON null.
      Specified by:
      arrayOpt in interface JsonObject
      Parameters:
      name - the property name
      Returns:
      the array value, or empty if missing or null
    • stringOpt

      public Optional<String> stringOpt(String name)
      Description copied from interface: JsonObject
      Returns the named string, or an empty optional when it is missing or JSON null.
      Specified by:
      stringOpt in interface JsonObject
      Parameters:
      name - the property name
      Returns:
      the string value, or empty if missing or null
    • boolOpt

      public Optional<Boolean> boolOpt(String name)
      Description copied from interface: JsonObject
      Returns the named boolean, or an empty optional when it is missing or JSON null.
      Specified by:
      boolOpt in interface JsonObject
      Parameters:
      name - the property name
      Returns:
      the boolean value, or empty if missing or null
    • decimalOpt

      public Optional<BigDecimal> decimalOpt(String name)
      Description copied from interface: JsonObject
      Returns the named number without precision loss.
      Specified by:
      decimalOpt in interface JsonObject
      Parameters:
      name - the property name
      Returns:
      the decimal value, or empty if missing or null
    • intOpt

      public OptionalInt intOpt(String name)
      Description copied from interface: JsonObject
      Returns the named exact int.
      Specified by:
      intOpt in interface JsonObject
      Parameters:
      name - the property name
      Returns:
      the int value, or empty if missing or null
    • longOpt

      public OptionalLong longOpt(String name)
      Description copied from interface: JsonObject
      Returns the named exact long.
      Specified by:
      longOpt in interface JsonObject
      Parameters:
      name - the property name
      Returns:
      the long value, or empty if missing or null
    • doubleOpt

      public OptionalDouble doubleOpt(String name)
      Description copied from interface: JsonObject
      Returns the named value converted to a finite double.

      The conversion may lose precision. Use JsonObject.decimalOpt(String) when an exact decimal representation is required.

      Specified by:
      doubleOpt in interface JsonObject
      Parameters:
      name - the property name
      Returns:
      the double value, or empty if missing or null
    • asMap

      public Map<String,Object> asMap()
      Description copied from interface: JsonObject
      Returns an immutable map representation.
      Specified by:
      asMap in interface JsonObject
      Returns:
      the map view
    • unwrap

      public <T> Optional<T> unwrap(Class<T> type)
      Description copied from interface: JsonDocument
      Returns the retained provider-specific representation when it matches type.

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

      Specified by:
      unwrap in interface JsonDocument
      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
    • json

      public String json()
      Description copied from interface: JsonDocument
      Returns the encoded JSON value.
      Specified by:
      json in interface JsonDocument
      Returns:
      the JSON string
    • toString

      public String toString()
      Returns the JSON representation, so an accidental string concatenation of Args (e.g. in a log line or a prompt/tool message) produces readable JSON instead of an opaque object identity.
      Overrides:
      toString in class Object
      Returns:
      the JSON string
    • rawJson

      public String rawJson()
      Returns the full arguments as a JSON string.
      Returns:
      the JSON string
    • decode

      public <T> T decode(Type targetType)
      Decodes the full arguments into the given type using the configured serde.
      Type Parameters:
      T - the target type
      Parameters:
      targetType - the target type
      Returns:
      the decoded value
      Throws:
      IllegalStateException - if no serde is configured
      InvalidArgumentException - if the arguments cannot be decoded into targetType; the dispatcher maps this to an invalid-params error rather than an internal failure
    • decode

      public <T> T decode(Class<T> targetClass)
      Decodes the full arguments into the given class using the configured serde.
      Type Parameters:
      T - the target type
      Parameters:
      targetClass - the target class
      Returns:
      the decoded value
      Throws:
      IllegalStateException - if no serde is configured