Class JsonUtils

java.lang.Object
dev.tachyonmcp.core.server.json.JsonUtils

@InternalApi public final class JsonUtils extends Object
  • Field Details

    • FACTORY

      public static final tools.jackson.core.json.JsonFactory FACTORY
    • TREE_READ_CONTEXT

      public static final tools.jackson.core.ObjectReadContext TREE_READ_CONTEXT
  • Method Details

    • parse

      public static tools.jackson.databind.JsonNode parse(String json)
    • parse

      public static tools.jackson.databind.JsonNode parse(JsonDocument document)
    • writeString

      public static String writeString(Object value)
    • toJsonNodeMap

      public static @Nullable Map<String,tools.jackson.databind.JsonNode> toJsonNodeMap(@Nullable Map<String,?> values)
    • toObjectMap

      public static @Nullable Map<String,Object> toObjectMap(@Nullable Map<String,tools.jackson.databind.JsonNode> values)
    • toObjectNode

      public static tools.jackson.databind.JsonNode toObjectNode(Map<String,?> fields)
      Builds an object JsonNode from an ordered field map, preserving field order and explicit null values (mapped to JSON null rather than omitted). Nested Map and List values are converted recursively; other values are serialized with the JSON-RPC serializer. Use it to emit hand-shaped wire objects for protocol versions that lack generated codecs.
    • parseJsonNode

      public static tools.jackson.databind.JsonNode parseJsonNode(String json)
    • valueToObjectNode

      public static <T> @Nullable tools.jackson.databind.JsonNode valueToObjectNode(@Nullable T value, PayloadSerializer serializer)
      Converts a given value into a JsonNode representing an object, if applicable. The method supports the following input types: - JsonDocument, where the contained JSON string is parsed into a JsonNode. - JsonNode, if it is already an object node. - Map, where its entries are transformed into an object node. - Other non-null values: serialized via the provided PayloadSerializer.
      Type Parameters:
      T - the type of the value to be converted
      Parameters:
      value - the value to be converted
      serializer - the serializer for non-tree values
      Returns:
      a JsonNode object node representation of the value, or null if the value cannot be converted
    • serializeStructured

      public static ToolResult serializeStructured(ToolResult result, PayloadSerializer serializer)
      Serializes non-tree structured values in a ToolResult into JsonDocument. JsonNode and JsonDocument pass through. Maps carrying JsonNode values are serialized with Jackson regardless of the configured serializer — a non-Jackson serde cannot encode Jackson trees.