Package io.modelcontextprotocol.json
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 TypeMethodDescription<T> TconvertValue(Object fromValue, TypeRef<T> type) Convert a value to a given parameterized type.<T> TconvertValue(Object fromValue, Class<T> type) Convert a value to a given type, useful for mapping nested JSON structures.static McpJsonMapperCreates a new defaultMcpJsonMapper.static McpJsonMapperReturns the defaultMcpJsonMapper.<T> TDeserialize JSON bytes into a parameterized target type.<T> TDeserialize JSON bytes into a target type.<T> TDeserialize JSON string into a parameterized target type.<T> TDeserialize JSON string into a target type.byte[]writeValueAsBytes(Object value) Serialize an object to JSON bytes.writeValueAsString(Object value) Serialize an object to JSON string.
-
Method Details
-
readValue
Deserialize JSON string into a target type.- Type Parameters:
T- generic type- Parameters:
content- JSON as Stringtype- target class- Returns:
- deserialized instance
- Throws:
IOException- on parse errors
-
readValue
Deserialize JSON bytes into a target type.- Type Parameters:
T- generic type- Parameters:
content- JSON as bytestype- target class- Returns:
- deserialized instance
- Throws:
IOException- on parse errors
-
readValue
Deserialize JSON string into a parameterized target type.- Type Parameters:
T- generic type- Parameters:
content- JSON as Stringtype- parameterized type reference- Returns:
- deserialized instance
- Throws:
IOException- on parse errors
-
readValue
Deserialize JSON bytes into a parameterized target type.- Type Parameters:
T- generic type- Parameters:
content- JSON as bytestype- parameterized type reference- Returns:
- deserialized instance
- Throws:
IOException- on parse errors
-
convertValue
Convert a value to a given type, useful for mapping nested JSON structures.- Type Parameters:
T- generic type- Parameters:
fromValue- source valuetype- target class- Returns:
- converted value
-
convertValue
Convert a value to a given parameterized type.- Type Parameters:
T- generic type- Parameters:
fromValue- source valuetype- target type reference- Returns:
- converted value
-
writeValueAsString
Serialize an object to JSON string.- Parameters:
value- object to serialize- Returns:
- JSON as String
- Throws:
IOException- on serialization errors
-
writeValueAsBytes
Serialize an object to JSON bytes.- Parameters:
value- object to serialize- Returns:
- JSON as bytes
- Throws:
IOException- on serialization errors
-
getDefault
Returns the defaultMcpJsonMapper.- Returns:
- The default
McpJsonMapper - Throws:
IllegalStateException- If noMcpJsonMapperimplementation exists on the classpath.
-
createDefault
Creates a new defaultMcpJsonMapper.- Returns:
- The default
McpJsonMapper - Throws:
IllegalStateException- If noMcpJsonMapperimplementation exists on the classpath.
-