Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mcp-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
<version>${jackson-annotations.version}</version>
</dependency>

<dependency>
Expand All @@ -100,7 +100,7 @@
<!-- Test dependencies -->
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp-json-jackson2</artifactId>
<artifactId>mcp-json-jackson3</artifactId>
<version>0.18.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -18,7 +19,7 @@

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
import tools.jackson.databind.exc.InvalidTypeIdException;

import io.modelcontextprotocol.spec.McpSchema.TextResourceContents;
import net.javacrumbs.jsonunit.core.Option;
Expand Down Expand Up @@ -59,6 +60,9 @@ void testContentDeserializationWrongType() throws Exception {

assertThatThrownBy(() -> JSON_MAPPER.readValue("""
{"type":"WRONG","text":"XXX"}""", McpSchema.TextContent.class))
.isInstanceOf(IOException.class)
.hasMessage("Failed to read value")
.cause()
.isInstanceOf(InvalidTypeIdException.class)
.hasMessageContaining(
"Could not resolve type id 'WRONG' as a subtype of `io.modelcontextprotocol.spec.McpSchema$TextContent`: known type ids = [audio, image, resource, resource_link, text]");
Expand Down
6 changes: 3 additions & 3 deletions mcp-json-jackson2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<artifactId>mcp-json-jackson2</artifactId>
<packaging>jar</packaging>
<name>Java MCP SDK JSON Jackson</name>
<description>Java MCP SDK JSON implementation based on Jackson</description>
<description>Java MCP SDK JSON implementation based on Jackson 2</description>
<url>https://github.com/modelcontextprotocol/java-sdk</url>
<scm>
<url>https://github.com/modelcontextprotocol/java-sdk</url>
Expand Down Expand Up @@ -42,12 +42,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<version>${jackson2.version}</version>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>${json-schema-validator.version}</version>
<version>${json-schema-validator-jackson2.version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
/**
* Jackson-based implementation of JsonMapper. Wraps a Jackson ObjectMapper but keeps the
* SDK decoupled from Jackson at the API level.
*
* @deprecated since 18.0.0, use
* {@link io.modelcontextprotocol.json.jackson2.JacksonMcpJsonMapper} instead. Will be
* removed in 19.0.0
*/
@Deprecated(forRemoval = true, since = "18.0.0")
public final class JacksonMcpJsonMapper implements McpJsonMapper {

private final ObjectMapper objectMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
* <p>
* This implementation provides a {@link McpJsonMapper} backed by a Jackson
* {@link com.fasterxml.jackson.databind.ObjectMapper}.
*
* @deprecated since 18.0.0, use
* {@link io.modelcontextprotocol.json.jackson2.JacksonMcpJsonMapperSupplier} instead.
* Will be removed in 19.0.0.
*/
@Deprecated(forRemoval = true, since = "18.0.0")
public class JacksonMcpJsonMapperSupplier implements McpJsonMapperSupplier {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2026 - 2026 the original author or authors.
*/

package io.modelcontextprotocol.json.jackson2;

import java.io.IOException;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.modelcontextprotocol.json.McpJsonMapper;
import io.modelcontextprotocol.json.TypeRef;

/**
* Jackson-based implementation of JsonMapper. Wraps a Jackson ObjectMapper but keeps the
* SDK decoupled from Jackson at the API level.
*/
public final class JacksonMcpJsonMapper implements McpJsonMapper {

private final ObjectMapper objectMapper;

/**
* Constructs a new JacksonMcpJsonMapper instance with the given ObjectMapper.
* @param objectMapper the ObjectMapper to be used for JSON serialization and
* deserialization. Must not be null.
* @throws IllegalArgumentException if the provided ObjectMapper is null.
*/
public JacksonMcpJsonMapper(ObjectMapper objectMapper) {
if (objectMapper == null) {
throw new IllegalArgumentException("ObjectMapper must not be null");
}
this.objectMapper = objectMapper;
}

/**
* Returns the underlying Jackson {@link ObjectMapper} used for JSON serialization and
* deserialization.
* @return the ObjectMapper instance
*/
public ObjectMapper getObjectMapper() {
return objectMapper;
}

@Override
public <T> T readValue(String content, Class<T> type) throws IOException {
return objectMapper.readValue(content, type);
}

@Override
public <T> T readValue(byte[] content, Class<T> type) throws IOException {
return objectMapper.readValue(content, type);
}

@Override
public <T> T readValue(String content, TypeRef<T> type) throws IOException {
JavaType javaType = objectMapper.getTypeFactory().constructType(type.getType());
return objectMapper.readValue(content, javaType);
}

@Override
public <T> T readValue(byte[] content, TypeRef<T> type) throws IOException {
JavaType javaType = objectMapper.getTypeFactory().constructType(type.getType());
return objectMapper.readValue(content, javaType);
}

@Override
public <T> T convertValue(Object fromValue, Class<T> type) {
return objectMapper.convertValue(fromValue, type);
}

@Override
public <T> T convertValue(Object fromValue, TypeRef<T> type) {
JavaType javaType = objectMapper.getTypeFactory().constructType(type.getType());
return objectMapper.convertValue(fromValue, javaType);
}

@Override
public String writeValueAsString(Object value) throws IOException {
return objectMapper.writeValueAsString(value);
}

@Override
public byte[] writeValueAsBytes(Object value) throws IOException {
return objectMapper.writeValueAsBytes(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2026 - 2026 the original author or authors.
*/

package io.modelcontextprotocol.json.jackson2;

import io.modelcontextprotocol.json.McpJsonMapper;
import io.modelcontextprotocol.json.McpJsonMapperSupplier;

/**
* A supplier of {@link McpJsonMapper} instances that uses the Jackson library for JSON
* serialization and deserialization.
* <p>
* This implementation provides a {@link McpJsonMapper} backed by a Jackson
* {@link com.fasterxml.jackson.databind.ObjectMapper}.
*/
public class JacksonMcpJsonMapperSupplier implements McpJsonMapperSupplier {

/**
* Returns a new instance of {@link McpJsonMapper} that uses the Jackson library for
* JSON serialization and deserialization.
* <p>
* The returned {@link McpJsonMapper} is backed by a new instance of
* {@link com.fasterxml.jackson.databind.ObjectMapper}.
* @return a new {@link McpJsonMapper} instance
*/
@Override
public McpJsonMapper get() {
return new JacksonMcpJsonMapper(new com.fasterxml.jackson.databind.ObjectMapper());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
* NetworkNT JSON Schema Validator library for validation.
*
* @author Christian Tzolov
* @deprecated since 18.0.0, use
* {@link io.modelcontextprotocol.json.schema.jackson2.DefaultJsonSchemaValidator}
* instead. Will be removed in 19.0.0.
*/
@Deprecated(forRemoval = true, since = "18.0.0")
public class DefaultJsonSchemaValidator implements JsonSchemaValidator {

private static final Logger logger = LoggerFactory.getLogger(DefaultJsonSchemaValidator.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*
* @see JsonSchemaValidatorSupplier
* @see JsonSchemaValidator
* @deprecated since 18.0.0, use
* {@link io.modelcontextprotocol.json.schema.jackson2.JacksonJsonSchemaValidatorSupplier}
* instead. Will be removed in 19.0.0.
*/
public class JacksonJsonSchemaValidatorSupplier implements JsonSchemaValidatorSupplier {

Expand Down
Loading