Class McpJson

java.lang.Object
dev.langchain4j.mcp.client.transport.McpJson

public final class McpJson extends Object
Bridges between JSON text and Jackson's tree model while both the deprecated JsonNode-based transport API and its replacement coexist.
  • Method Details

    • deserialize

      public static <T> T deserialize(com.fasterxml.jackson.databind.JsonNode message, Class<T> type)
      Deserializes an MCP message into a protocol type.
    • toValue

      public static Object toValue(String json)
      Reads any JSON value as plain JDK types: a Map, a List, a boxed primitive, or null for a JSON null.
      Throws:
      IllegalArgumentException - if the text is not valid JSON.
    • toMap

      public static Map<String,Object> toMap(String json)
      Reads a JSON object as plain values.
    • convert

      public static <T> T convert(Object value, Class<T> type)
      Re-reads an already-decoded JSON value as the given type.
    • convertList

      public static <T> List<T> convertList(Object value, Class<T> elementType)
      Re-reads an already-decoded JSON array as a list of the given element type.
    • serialize

      public static String serialize(Object message)
      Serializes an outbound MCP message. A null message renders as null rather than as the JSON null literal, so that an absent payload stays absent.
    • parse

      public static com.fasterxml.jackson.databind.JsonNode parse(String json)
    • map

      public static <T,R> CompletableFuture<R> map(CompletableFuture<T> source, Function<T,R> mapper)
      Maps a future's value while keeping cancellation linked to the source. A plain thenApply would not propagate cancellation upstream, which would leave the transport's response stream open after the client cancels the operation.