Interface McpJsonMapper


public interface McpJsonMapper
Abstraction for JSON serialization/deserialization to decouple the SDK from any specific JSON library. A default implementation backed by Jackson is provided in io.modelcontextprotocol.spec.json.jackson.JacksonJsonMapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    convertValue(Object fromValue, TypeRef<T> type)
    Convert a value to a given parameterized type.
    <T> T
    convertValue(Object fromValue, Class<T> type)
    Convert a value to a given type, useful for mapping nested JSON structures.
    <T> T
    readValue(byte[] content, TypeRef<T> type)
    Deserialize JSON bytes into a parameterized target type.
    <T> T
    readValue(byte[] content, Class<T> type)
    Deserialize JSON bytes into a target type.
    <T> T
    readValue(String content, TypeRef<T> type)
    Deserialize JSON string into a parameterized target type.
    <T> T
    readValue(String content, Class<T> type)
    Deserialize JSON string into a target type.
    byte[]
    Serialize an object to JSON bytes.
    Serialize an object to JSON string.
  • Method Details

    • readValue

      <T> T readValue(String content, Class<T> type) throws IOException
      Deserialize JSON string into a target type.
      Type Parameters:
      T - generic type
      Parameters:
      content - JSON as String
      type - target class
      Returns:
      deserialized instance
      Throws:
      IOException - on parse errors
    • readValue

      <T> T readValue(byte[] content, Class<T> type) throws IOException
      Deserialize JSON bytes into a target type.
      Type Parameters:
      T - generic type
      Parameters:
      content - JSON as bytes
      type - target class
      Returns:
      deserialized instance
      Throws:
      IOException - on parse errors
    • readValue

      <T> T readValue(String content, TypeRef<T> type) throws IOException
      Deserialize JSON string into a parameterized target type.
      Type Parameters:
      T - generic type
      Parameters:
      content - JSON as String
      type - parameterized type reference
      Returns:
      deserialized instance
      Throws:
      IOException - on parse errors
    • readValue

      <T> T readValue(byte[] content, TypeRef<T> type) throws IOException
      Deserialize JSON bytes into a parameterized target type.
      Type Parameters:
      T - generic type
      Parameters:
      content - JSON as bytes
      type - parameterized type reference
      Returns:
      deserialized instance
      Throws:
      IOException - on parse errors
    • convertValue

      <T> T convertValue(Object fromValue, Class<T> type)
      Convert a value to a given type, useful for mapping nested JSON structures.
      Type Parameters:
      T - generic type
      Parameters:
      fromValue - source value
      type - target class
      Returns:
      converted value
    • convertValue

      <T> T convertValue(Object fromValue, TypeRef<T> type)
      Convert a value to a given parameterized type.
      Type Parameters:
      T - generic type
      Parameters:
      fromValue - source value
      type - target type reference
      Returns:
      converted value
    • writeValueAsString

      String writeValueAsString(Object value) throws IOException
      Serialize an object to JSON string.
      Parameters:
      value - object to serialize
      Returns:
      JSON as String
      Throws:
      IOException - on serialization errors
    • writeValueAsBytes

      byte[] writeValueAsBytes(Object value) throws IOException
      Serialize an object to JSON bytes.
      Parameters:
      value - object to serialize
      Returns:
      JSON as bytes
      Throws:
      IOException - on serialization errors