You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/08/15 16:28:14 UTC
(shardingsphere) branch master updated: Isolate Jackson implementation behind JsonUtils (#39473)
This is an automated email from the ASF dual-hosted git repository.
terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b9753d22de8 Isolate Jackson implementation behind JsonUtils (#39473)
b9753d22de8 is described below
commit b9753d22de8621e41659f5ab1ffc1b14113b6bf4
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Aug 16 00:28:08 2026 +0800
Isolate Jackson implementation behind JsonUtils (#39473)
---
.../infra/util/json/JsonException.java | 25 +++------
.../infra/util/json/JsonTypeReference.java | 35 ++++++------
.../shardingsphere/infra/util/json/JsonUtils.java | 54 +++++++++++-------
.../infra/util/json/JsonTypeReferenceTest.java | 29 ++++------
.../infra/util/json/JsonUtilsTest.java | 64 +++++++++++++++-------
.../transport/MCPTransportJsonMapperFactory.java | 14 ++++-
.../resource/MCPResourceSpecificationFactory.java | 7 ++-
.../capability/tool/MCPCallToolResultFactory.java | 19 ++++++-
.../AbstractMCPToolSpecificationFactoryTest.java | 4 +-
.../server/http/StreamableHttpMCPServerIT.java | 10 ++--
.../metadata/GovernanceMetadataQueryService.java | 13 +----
mcp/registry/pom.xml | 5 --
.../mcp/registry/MCPRegistryMetadataCommand.java | 9 +--
.../registry/MCPRegistryMetadataCommandTest.java | 9 +--
.../workflow/service/WorkflowAlgorithmUtils.java | 10 ++--
.../imports/ImportMetaDataExecutorTest.java | 4 +-
.../e2e/agent/zipkin/asserts/ZipkinSpanAssert.java | 4 +-
.../e2e/mcp/llm/conversation/LLMMCPJsonValues.java | 11 ++--
.../conversation/client/LLMChatModelClient.java | 4 +-
.../support/transport/MCPInteractionPayloads.java | 12 ++--
.../transport/MCPInteractionProtocolSupport.java | 18 +++++-
.../AbstractProcessMCPStdioInteractionClient.java | 12 ++--
test/it/parser/pom.xml | 4 --
.../type/GitHubTestParameterLoadStrategy.java | 31 ++++-------
24 files changed, 217 insertions(+), 190 deletions(-)
diff --git a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/json/JsonException.java
similarity index 56%
copy from mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java
copy to infra/util/src/main/java/org/apache/shardingsphere/infra/util/json/JsonException.java
index 4fc9e430734..774e5d8c036 100644
--- a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/json/JsonException.java
@@ -15,27 +15,16 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mcp.bootstrap.transport;
-
-import io.modelcontextprotocol.json.McpJsonMapper;
-import io.modelcontextprotocol.json.jackson2.JacksonMcpJsonMapper;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
+package org.apache.shardingsphere.infra.util.json;
/**
- * MCP transport JSON mapper factory.
+ * JSON exception.
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MCPTransportJsonMapperFactory {
+public final class JsonException extends RuntimeException {
- /**
- * Create MCP JSON mapper.
- *
- * @return MCP JSON mapper
- */
- public static McpJsonMapper create() {
- return new JacksonMcpJsonMapper(JsonUtils.createObjectMapper());
- }
+ private static final long serialVersionUID = -3509683613619627144L;
+ JsonException(final Exception cause) {
+ super(cause.getMessage(), cause);
+ }
}
diff --git a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/json/JsonTypeReference.java
similarity index 50%
copy from mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java
copy to infra/util/src/main/java/org/apache/shardingsphere/infra/util/json/JsonTypeReference.java
index 4fc9e430734..9d238a44af8 100644
--- a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/json/JsonTypeReference.java
@@ -15,27 +15,30 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mcp.bootstrap.transport;
+package org.apache.shardingsphere.infra.util.json;
-import io.modelcontextprotocol.json.McpJsonMapper;
-import io.modelcontextprotocol.json.jackson2.JacksonMcpJsonMapper;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
+import org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
/**
- * MCP transport JSON mapper factory.
+ * JSON type reference.
+ *
+ * @param <T> referenced type
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MCPTransportJsonMapperFactory {
+public abstract class JsonTypeReference<T> {
- /**
- * Create MCP JSON mapper.
- *
- * @return MCP JSON mapper
- */
- public static McpJsonMapper create() {
- return new JacksonMcpJsonMapper(JsonUtils.createObjectMapper());
+ private final Type type;
+
+ protected JsonTypeReference() {
+ Type genericSuperclass = getClass().getGenericSuperclass();
+ ShardingSpherePreconditions.checkState(genericSuperclass instanceof ParameterizedType,
+ () -> new IllegalArgumentException("JsonTypeReference must be constructed with actual type information."));
+ type = ((ParameterizedType) genericSuperclass).getActualTypeArguments()[0];
}
+ final Type getType() {
+ return type;
+ }
}
diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/json/JsonUtils.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/json/JsonUtils.java
index 40b07a66ef7..90cc68d83f5 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/json/JsonUtils.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/json/JsonUtils.java
@@ -19,14 +19,12 @@ package org.apache.shardingsphere.infra.util.json;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
/**
* Json utility class.
@@ -51,23 +49,33 @@ public final class JsonUtils {
}
/**
- * Create object mapper with ShardingSphere JSON configurations.
+ * Serialize object as json string.
*
- * @return object mapper
+ * @param obj object
+ * @return json string
+ * @throws JsonException when object cannot be serialized
*/
- public static ObjectMapper createObjectMapper() {
- return MAPPER.copy();
+ public static String toJsonString(final Object obj) {
+ try {
+ return MAPPER.writeValueAsString(obj);
+ } catch (final JsonProcessingException ex) {
+ throw new JsonException(ex);
+ }
}
/**
- * Serialize object as json string.
+ * Serialize object as pretty JSON string.
*
* @param obj object
- * @return json string
+ * @return pretty JSON string
+ * @throws JsonException when object cannot be serialized
*/
- @SneakyThrows(JsonProcessingException.class)
- public static String toJsonString(final Object obj) {
- return MAPPER.writeValueAsString(obj);
+ public static String toPrettyJsonString(final Object obj) {
+ try {
+ return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
+ } catch (final JsonProcessingException ex) {
+ throw new JsonException(ex);
+ }
}
/**
@@ -77,22 +85,30 @@ public final class JsonUtils {
* @param clazz target object type
* @param <T> the type of target object
* @return object
+ * @throws JsonException when JSON cannot be deserialized
*/
- @SneakyThrows(JsonProcessingException.class)
- public static <T extends JsonConfiguration> T fromJsonString(final String value, final Class<T> clazz) {
- return MAPPER.readValue(value, clazz);
+ public static <T> T fromJsonString(final String value, final Class<T> clazz) {
+ try {
+ return MAPPER.readValue(value, clazz);
+ } catch (final JsonProcessingException ex) {
+ throw new JsonException(ex);
+ }
}
/**
- * Deserialize from json string to object.
+ * Deserialize from JSON string to object.
*
- * @param value json string
+ * @param value JSON string
* @param typeReference target object type reference
* @param <T> the type of target object
* @return object
+ * @throws JsonException when JSON cannot be deserialized
*/
- @SneakyThrows(JsonProcessingException.class)
- public static <T> T fromJsonString(final String value, final TypeReference<T> typeReference) {
- return MAPPER.readValue(value, typeReference);
+ public static <T> T fromJsonString(final String value, final JsonTypeReference<T> typeReference) {
+ try {
+ return MAPPER.readValue(value, MAPPER.getTypeFactory().constructType(typeReference.getType()));
+ } catch (final JsonProcessingException ex) {
+ throw new JsonException(ex);
+ }
}
}
diff --git a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/json/JsonTypeReferenceTest.java
similarity index 55%
copy from mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java
copy to infra/util/src/test/java/org/apache/shardingsphere/infra/util/json/JsonTypeReferenceTest.java
index 4fc9e430734..ab5e1f593f9 100644
--- a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/json/JsonTypeReferenceTest.java
@@ -15,27 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mcp.bootstrap.transport;
+package org.apache.shardingsphere.infra.util.json;
-import io.modelcontextprotocol.json.McpJsonMapper;
-import io.modelcontextprotocol.json.jackson2.JacksonMcpJsonMapper;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
+import org.junit.jupiter.api.Test;
-/**
- * MCP transport JSON mapper factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MCPTransportJsonMapperFactory {
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class JsonTypeReferenceTest {
- /**
- * Create MCP JSON mapper.
- *
- * @return MCP JSON mapper
- */
- public static McpJsonMapper create() {
- return new JacksonMcpJsonMapper(JsonUtils.createObjectMapper());
+ @SuppressWarnings("rawtypes")
+ @Test
+ void assertConstructWithoutActualTypeInformation() {
+ assertThrows(IllegalArgumentException.class, () -> new JsonTypeReference() {
+ });
}
-
}
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/json/JsonUtilsTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/json/JsonUtilsTest.java
index c48a868972e..6401a8448cd 100644
--- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/json/JsonUtilsTest.java
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/json/JsonUtilsTest.java
@@ -17,33 +17,36 @@
package org.apache.shardingsphere.infra.util.json;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
+import lombok.Getter;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.api.Test;
+import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
+import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
class JsonUtilsTest {
- @Test
- void assertCreateObjectMapper() {
- ObjectMapper actual = JsonUtils.createObjectMapper();
- assertTrue(actual.getRegisteredModuleIds().contains("jackson-datatype-jsr310"));
- assertTrue(actual.getRegisteredModuleIds().contains("com.fasterxml.jackson.datatype.jdk8.Jdk8Module"));
- assertFalse(actual.isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS));
- assertFalse(actual.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
- assertThat(actual.getSerializationConfig().getDefaultPropertyInclusion().getValueInclusion(), is(Include.NON_NULL));
- actual.enable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
- assertThat(JsonUtils.toJsonString(new Object()), is("{}"));
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("getJsonConfigurationArguments")
+ void assertJsonConfigurations(final String name, final Object value, final String expected) {
+ assertThat(JsonUtils.toJsonString(value), is(expected));
+ }
+
+ private static Stream<Arguments> getJsonConfigurationArguments() {
+ return Stream.of(
+ Arguments.of("empty beans", new Object(), "{}"),
+ Arguments.of("Java time", Collections.singletonMap("date", LocalDate.of(2025, 4, 9)), "{\"date\":[2025,4,9]}"),
+ Arguments.of("JDK optional", Collections.singletonMap("optional", Optional.of("foo")), "{\"optional\":\"foo\"}"),
+ Arguments.of("null property", Collections.singletonMap("ignored", null), "{}"));
}
@Test
@@ -51,16 +54,37 @@ class JsonUtilsTest {
assertThat(JsonUtils.toJsonString(Collections.singletonMap("k", "v")), is("{\"k\":\"v\"}"));
}
+ @Test
+ void assertToPrettyJsonString() {
+ assertThat(JsonUtils.toPrettyJsonString(Collections.singletonMap("k", "v")), is("{" + System.lineSeparator() + " \"k\" : \"v\"" + System.lineSeparator() + "}"));
+ }
+
@Test
void assertFromJsonStringToClass() {
- assertThat(JsonUtils.fromJsonString("{\"name\":\"foo\"}", JsonConfigurationFixture.class).getName(), is("foo"));
+ assertThat(JsonUtils.fromJsonString("{\"name\":\"foo\",\"ignored\":true}", JsonConfigurationFixture.class).getName(), is("foo"));
}
@Test
- void assertFromJsonStringToTypeReference() {
- List<JsonConfigurationFixture> actual = JsonUtils.fromJsonString("[{\"name\":\"foo\"}]", new TypeReference<List<JsonConfigurationFixture>>() {
+ void assertFromJsonStringToJsonTypeReference() {
+ List<JsonConfigurationFixture> actual = JsonUtils.fromJsonString("[{\"name\":\"foo\"}]", new JsonTypeReference<List<JsonConfigurationFixture>>() {
});
assertThat(actual.size(), is(1));
assertThat(actual.iterator().next().getName(), is("foo"));
}
+
+ @Test
+ void assertFromMalformedJsonString() {
+ assertThrows(JsonException.class, () -> JsonUtils.fromJsonString("{", Object.class));
+ }
+
+ @Test
+ void assertSerializeCyclicObject() {
+ assertThrows(JsonException.class, () -> JsonUtils.toJsonString(new CyclicFixture()));
+ }
+
+ @Getter
+ private static final class CyclicFixture {
+
+ private final CyclicFixture value = this;
+ }
}
diff --git a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java b/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java
index 4fc9e430734..15658a41954 100644
--- a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java
+++ b/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/MCPTransportJsonMapperFactory.java
@@ -17,11 +17,15 @@
package org.apache.shardingsphere.mcp.bootstrap.transport;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.modelcontextprotocol.json.McpJsonMapper;
import io.modelcontextprotocol.json.jackson2.JacksonMcpJsonMapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
/**
* MCP transport JSON mapper factory.
@@ -35,7 +39,13 @@ public final class MCPTransportJsonMapperFactory {
* @return MCP JSON mapper
*/
public static McpJsonMapper create() {
- return new JacksonMcpJsonMapper(JsonUtils.createObjectMapper());
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.registerModule(new JavaTimeModule());
+ objectMapper.findAndRegisterModules();
+ objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
+ objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ objectMapper.setSerializationInclusion(Include.NON_NULL);
+ return new JacksonMcpJsonMapper(objectMapper);
}
}
diff --git a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/resource/MCPResourceSpecificationFactory.java b/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/resource/MCPResourceSpecificationFactory.java
index e479b175582..0a897e2c73c 100644
--- a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/resource/MCPResourceSpecificationFactory.java
+++ b/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/resource/MCPResourceSpecificationFactory.java
@@ -17,15 +17,16 @@
package org.apache.shardingsphere.mcp.bootstrap.transport.capability.resource;
+import io.modelcontextprotocol.json.McpJsonMapper;
import io.modelcontextprotocol.server.McpServerFeatures.SyncResourceSpecification;
import io.modelcontextprotocol.server.McpServerFeatures.SyncResourceTemplateSpecification;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.McpSchema.ReadResourceResult;
import io.modelcontextprotocol.spec.McpSchema.TextResourceContents;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
import org.apache.shardingsphere.mcp.api.capability.resource.MCPResourceAnnotations;
import org.apache.shardingsphere.mcp.api.capability.resource.MCPResourceDescriptor;
import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportErrorFactory;
+import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportJsonMapperFactory;
import org.apache.shardingsphere.mcp.core.context.MCPRuntimeContext;
import org.apache.shardingsphere.mcp.core.resource.MCPResourceController;
import org.apache.shardingsphere.mcp.core.resource.handler.ResourceDefinitionRegistry;
@@ -43,6 +44,8 @@ public final class MCPResourceSpecificationFactory {
private static final String JSON_CONTENT_TYPE = "application/json";
+ private final McpJsonMapper jsonMapper = MCPTransportJsonMapperFactory.create();
+
private final Collection<MCPResourceDescriptor> descriptors;
private final MCPResourceController controller;
@@ -114,7 +117,7 @@ public final class MCPResourceSpecificationFactory {
private ReadResourceResult readResource(final String sessionId, final McpSchema.ReadResourceRequest request) {
try {
Map<String, Object> payload = controller.handle(sessionId, request.uri()).toPayload();
- return new ReadResourceResult(Collections.singletonList(new TextResourceContents(request.uri(), JSON_CONTENT_TYPE, JsonUtils.toJsonString(payload))));
+ return new ReadResourceResult(Collections.singletonList(new TextResourceContents(request.uri(), JSON_CONTENT_TYPE, jsonMapper.writeValueAsString(payload))));
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
diff --git a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/tool/MCPCallToolResultFactory.java b/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/tool/MCPCallToolResultFactory.java
index 96ea0aa5310..52efa741793 100644
--- a/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/tool/MCPCallToolResultFactory.java
+++ b/mcp/bootstrap/src/main/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/tool/MCPCallToolResultFactory.java
@@ -17,17 +17,20 @@
package org.apache.shardingsphere.mcp.bootstrap.transport.capability.tool;
+import io.modelcontextprotocol.json.McpJsonMapper;
import io.modelcontextprotocol.json.schema.JsonSchemaValidator;
import io.modelcontextprotocol.json.schema.JsonSchemaValidator.ValidationResponse;
import io.modelcontextprotocol.json.schema.jackson2.DefaultJsonSchemaValidator;
import io.modelcontextprotocol.spec.McpSchema.CallToolResult;
import io.modelcontextprotocol.spec.McpSchema;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
import org.apache.shardingsphere.mcp.api.payload.MCPSuccessPayload;
import org.apache.shardingsphere.mcp.api.capability.tool.MCPToolDescriptor;
+import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportErrorFactory;
+import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportJsonMapperFactory;
import org.apache.shardingsphere.mcp.core.protocol.error.MCPErrorPayload;
import org.apache.shardingsphere.mcp.support.descriptor.MCPShardingSphereMetadataKeys;
+import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
@@ -36,6 +39,8 @@ final class MCPCallToolResultFactory {
private static final int RESOURCE_LINK_LIMIT = 24;
+ private final McpJsonMapper jsonMapper = MCPTransportJsonMapperFactory.create();
+
private final JsonSchemaValidator outputSchemaValidator = new DefaultJsonSchemaValidator();
CallToolResult create(final MCPToolDescriptor descriptor, final MCPSuccessPayload successPayload) {
@@ -52,17 +57,25 @@ final class MCPCallToolResultFactory {
CallToolResult create(final MCPErrorPayload errorPayload) {
Map<String, Object> payload = errorPayload.toPayload();
- CallToolResult.Builder result = CallToolResult.builder().addTextContent(JsonUtils.toJsonString(payload)).isError(true);
+ CallToolResult.Builder result = CallToolResult.builder().addTextContent(toJsonString(payload)).isError(true);
appendResourceLinks(payload, result);
return result.build();
}
private CallToolResult createSuccess(final Map<String, Object> payload) {
- CallToolResult.Builder result = CallToolResult.builder().structuredContent(payload).addTextContent(JsonUtils.toJsonString(payload)).isError(false);
+ CallToolResult.Builder result = CallToolResult.builder().structuredContent(payload).addTextContent(toJsonString(payload)).isError(false);
appendResourceLinks(payload, result);
return result.build();
}
+ private String toJsonString(final Object value) {
+ try {
+ return jsonMapper.writeValueAsString(value);
+ } catch (final IOException ex) {
+ throw MCPTransportErrorFactory.createError(ex);
+ }
+ }
+
private void appendResourceLinks(final Map<String, Object> payload, final CallToolResult.Builder builder) {
MCPResourceLinkCandidateCollector.ResourceLinkCandidates candidates = new MCPResourceLinkCandidateCollector(RESOURCE_LINK_LIMIT).collect(payload);
int emittedCount = 0;
diff --git a/mcp/bootstrap/src/test/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/tool/AbstractMCPToolSpecificationFactoryTest.java b/mcp/bootstrap/src/test/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/tool/AbstractMCPToolSpecificationFactoryTest.java
index 156279c1ccf..ffd8484fafe 100644
--- a/mcp/bootstrap/src/test/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/tool/AbstractMCPToolSpecificationFactoryTest.java
+++ b/mcp/bootstrap/src/test/java/org/apache/shardingsphere/mcp/bootstrap/transport/capability/tool/AbstractMCPToolSpecificationFactoryTest.java
@@ -18,13 +18,13 @@
package org.apache.shardingsphere.mcp.bootstrap.transport.capability.tool;
import org.apache.shardingsphere.mcp.api.session.MCPSessionIdentity;
-import com.fasterxml.jackson.core.type.TypeReference;
import io.modelcontextprotocol.server.McpServerFeatures.SyncToolSpecification;
import io.modelcontextprotocol.server.McpSyncServerExchange;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.McpSchema.CallToolRequest;
import io.modelcontextprotocol.spec.McpSchema.CallToolResult;
import io.modelcontextprotocol.spec.McpSchema.TextContent;
+import org.apache.shardingsphere.infra.util.json.JsonTypeReference;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
import org.apache.shardingsphere.mcp.api.payload.MCPSuccessPayload;
import org.apache.shardingsphere.mcp.api.transport.MCPTransportType;
@@ -179,7 +179,7 @@ abstract class AbstractMCPToolSpecificationFactoryTest {
}
protected Map<String, Object> getTextContentPayload(final CallToolResult actual) {
- return JsonUtils.fromJsonString(((TextContent) actual.content().getFirst()).text(), new TypeReference<>() {
+ return JsonUtils.fromJsonString(((TextContent) actual.content().getFirst()).text(), new JsonTypeReference<>() {
});
}
diff --git a/mcp/bootstrap/src/test/java/org/apache/shardingsphere/mcp/bootstrap/transport/server/http/StreamableHttpMCPServerIT.java b/mcp/bootstrap/src/test/java/org/apache/shardingsphere/mcp/bootstrap/transport/server/http/StreamableHttpMCPServerIT.java
index c0ebd6693a8..f5bbe7460c7 100644
--- a/mcp/bootstrap/src/test/java/org/apache/shardingsphere/mcp/bootstrap/transport/server/http/StreamableHttpMCPServerIT.java
+++ b/mcp/bootstrap/src/test/java/org/apache/shardingsphere/mcp/bootstrap/transport/server/http/StreamableHttpMCPServerIT.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.mcp.bootstrap.transport.server.http;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
+import io.modelcontextprotocol.json.McpJsonMapper;
import org.apache.shardingsphere.mcp.api.transport.MCPTransportType;
import org.apache.shardingsphere.mcp.bootstrap.config.HttpTransportConfiguration;
import org.apache.shardingsphere.mcp.bootstrap.config.SessionAttributionSourceConfiguration;
import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportConstants;
+import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportJsonMapperFactory;
import org.apache.shardingsphere.mcp.core.context.MCPRuntimeContext;
import org.apache.shardingsphere.mcp.core.session.MCPSessionManager;
import org.apache.shardingsphere.mcp.support.database.capability.MCPDatabaseCapabilityProvider;
@@ -46,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class StreamableHttpMCPServerIT {
- private static final ObjectMapper OBJECT_MAPPER = JsonUtils.createObjectMapper();
+ private static final McpJsonMapper JSON_MAPPER = MCPTransportJsonMapperFactory.create();
private static final String CONTENT_TYPE_HEADER = "Content-Type";
@@ -226,7 +226,7 @@ class StreamableHttpMCPServerIT {
}
private HttpResponse<String> sendPost(final Map<String, Object> payload, final Map<String, String> headers) throws IOException, InterruptedException {
- HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(endpoint).POST(HttpRequest.BodyPublishers.ofString(OBJECT_MAPPER.writeValueAsString(payload)));
+ HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(endpoint).POST(HttpRequest.BodyPublishers.ofString(JSON_MAPPER.writeValueAsString(payload)));
headers.forEach(requestBuilder::header);
return httpClient.send(requestBuilder.build(), HttpResponse.BodyHandlers.ofString());
}
@@ -269,7 +269,7 @@ class StreamableHttpMCPServerIT {
}
private Map<?, ?> parseBody(final HttpResponse<String> response) throws IOException {
- return OBJECT_MAPPER.readValue(normalizeJsonBody(response.body()), Map.class);
+ return JSON_MAPPER.readValue(normalizeJsonBody(response.body()), Map.class);
}
private String normalizeJsonBody(final String responseBody) {
diff --git a/mcp/core/src/main/java/org/apache/shardingsphere/mcp/core/metadata/GovernanceMetadataQueryService.java b/mcp/core/src/main/java/org/apache/shardingsphere/mcp/core/metadata/GovernanceMetadataQueryService.java
index a5d8560ac51..7de985a9b70 100644
--- a/mcp/core/src/main/java/org/apache/shardingsphere/mcp/core/metadata/GovernanceMetadataQueryService.java
+++ b/mcp/core/src/main/java/org/apache/shardingsphere/mcp/core/metadata/GovernanceMetadataQueryService.java
@@ -17,9 +17,7 @@
package org.apache.shardingsphere.mcp.core.metadata;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.shardingsphere.infra.util.json.JsonException;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
import org.apache.shardingsphere.mcp.support.database.spi.MCPFeatureQueryFacade;
import org.apache.shardingsphere.mcp.support.workflow.service.WorkflowSQLUtils;
@@ -38,11 +36,6 @@ import java.util.Objects;
*/
public final class GovernanceMetadataQueryService {
- private static final ObjectMapper OBJECT_MAPPER = JsonUtils.createObjectMapper();
-
- private static final TypeReference<Object> JSON_VALUE_TYPE = new TypeReference<>() {
- };
-
private static final String REDACTED_VALUE = "******";
/**
@@ -199,8 +192,8 @@ public final class GovernanceMetadataQueryService {
return new RedactedValue(value, false);
}
try {
- return redactNested(OBJECT_MAPPER.readValue(text, JSON_VALUE_TYPE));
- } catch (final JsonProcessingException ignored) {
+ return redactNested(JsonUtils.fromJsonString(text, Object.class));
+ } catch (final JsonException ignored) {
return new RedactedValue(value, false);
}
}
diff --git a/mcp/registry/pom.xml b/mcp/registry/pom.xml
index d69ee2b8861..4777596fa3b 100644
--- a/mcp/registry/pom.xml
+++ b/mcp/registry/pom.xml
@@ -37,10 +37,5 @@
<artifactId>shardingsphere-infra-util</artifactId>
<version>${project.version}</version>
</dependency>
-
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- </dependency>
</dependencies>
</project>
diff --git a/mcp/registry/src/main/java/org/apache/shardingsphere/mcp/registry/MCPRegistryMetadataCommand.java b/mcp/registry/src/main/java/org/apache/shardingsphere/mcp/registry/MCPRegistryMetadataCommand.java
index d0179e885ed..59092ad9fc4 100644
--- a/mcp/registry/src/main/java/org/apache/shardingsphere/mcp/registry/MCPRegistryMetadataCommand.java
+++ b/mcp/registry/src/main/java/org/apache/shardingsphere/mcp/registry/MCPRegistryMetadataCommand.java
@@ -17,11 +17,10 @@
package org.apache.shardingsphere.mcp.registry;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.util.json.JsonTypeReference;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
import java.io.IOException;
@@ -41,8 +40,6 @@ import java.util.regex.Pattern;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MCPRegistryMetadataCommand {
- private static final ObjectMapper JSON_MAPPER = JsonUtils.createObjectMapper();
-
private static final String REGISTRY_SCHEMA_URL = "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json";
private static final String SERVER_NAME = "io.github.apache/shardingsphere-mcp";
@@ -84,7 +81,7 @@ public final class MCPRegistryMetadataCommand {
*/
public static void execute(final String... args) throws IOException {
CommandOptions options = parseOptions(args);
- Map<String, Object> server = JSON_MAPPER.readValue(options.path().toFile(), new TypeReference<>() {
+ Map<String, Object> server = JsonUtils.fromJsonString(Files.readString(options.path()), new JsonTypeReference<Map<String, Object>>() {
});
if (!options.validateOnly()) {
ShardingSpherePreconditions.checkState(!options.version().isBlank() && !options.identifier().isBlank(),
@@ -96,7 +93,7 @@ public final class MCPRegistryMetadataCommand {
MCPDockerfileMetadataValidator.validate(Path.of(options.dockerfilePath()), String.valueOf(server.get("name")));
}
if (!options.validateOnly()) {
- Files.writeString(options.path(), JSON_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(server) + System.lineSeparator());
+ Files.writeString(options.path(), JsonUtils.toPrettyJsonString(server) + System.lineSeparator());
}
}
diff --git a/mcp/registry/src/test/java/org/apache/shardingsphere/mcp/registry/MCPRegistryMetadataCommandTest.java b/mcp/registry/src/test/java/org/apache/shardingsphere/mcp/registry/MCPRegistryMetadataCommandTest.java
index 8afb458cb92..2ffe1a3d804 100644
--- a/mcp/registry/src/test/java/org/apache/shardingsphere/mcp/registry/MCPRegistryMetadataCommandTest.java
+++ b/mcp/registry/src/test/java/org/apache/shardingsphere/mcp/registry/MCPRegistryMetadataCommandTest.java
@@ -17,8 +17,7 @@
package org.apache.shardingsphere.mcp.registry;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.shardingsphere.infra.util.json.JsonTypeReference;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -38,8 +37,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class MCPRegistryMetadataCommandTest {
- private static final ObjectMapper JSON_MAPPER = JsonUtils.createObjectMapper();
-
private static final String REGISTRY_SCHEMA_URL = "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json";
private static final String PACKAGE_SHAPE_ERROR_MESSAGE = "server.json packages must contain exactly one stdio OCI package and one streamable-http OCI package.";
@@ -239,7 +236,7 @@ class MCPRegistryMetadataCommandTest {
private Path createServerJson(final Map<String, Object> server) throws IOException {
Path result = tempDir.resolve("server.json");
- Files.writeString(result, JSON_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(server));
+ Files.writeString(result, JsonUtils.toPrettyJsonString(server));
return result;
}
@@ -281,7 +278,7 @@ class MCPRegistryMetadataCommandTest {
}
private Map<String, Object> readServerJson(final Path serverPath) throws IOException {
- return JSON_MAPPER.readValue(serverPath.toFile(), new TypeReference<>() {
+ return JsonUtils.fromJsonString(Files.readString(serverPath), new JsonTypeReference<Map<String, Object>>() {
});
}
diff --git a/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/workflow/service/WorkflowAlgorithmUtils.java b/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/workflow/service/WorkflowAlgorithmUtils.java
index 0c4021f224f..52dfc7d6241 100644
--- a/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/workflow/service/WorkflowAlgorithmUtils.java
+++ b/mcp/support/src/main/java/org/apache/shardingsphere/mcp/support/workflow/service/WorkflowAlgorithmUtils.java
@@ -17,14 +17,14 @@
package org.apache.shardingsphere.mcp.support.workflow.service;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.exception.external.ShardingSphereExternalException;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.infra.util.json.JsonException;
+import org.apache.shardingsphere.infra.util.json.JsonTypeReference;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
import org.apache.shardingsphere.mcp.support.workflow.model.SecretReferenceValue;
@@ -45,7 +45,7 @@ public final class WorkflowAlgorithmUtils {
private static final String ALGORITHM_TYPE_KEY = "type";
- private static final TypeReference<Map<?, ?>> JSON_PROPERTY_MAP_TYPE = new TypeReference<>() {
+ private static final JsonTypeReference<Map<?, ?>> JSON_PROPERTY_MAP_TYPE = new JsonTypeReference<Map<?, ?>>() {
};
/**
@@ -179,14 +179,14 @@ public final class WorkflowAlgorithmUtils {
}
try {
return parseJSONPropertyString(actualValue);
- } catch (final JsonProcessingException ignored) {
+ } catch (final JsonException ignored) {
return Map.of();
}
}
return parseLegacyPropertyString(actualValue);
}
- private static Map<String, String> parseJSONPropertyString(final String value) throws JsonProcessingException {
+ private static Map<String, String> parseJSONPropertyString(final String value) {
return createPropertyMap(JsonUtils.fromJsonString(value, JSON_PROPERTY_MAP_TYPE));
}
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/imports/ImportMetaDataExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/imports/ImportMetaDataExecutorTest.java
index cffe8c205d7..34e45b0cc04 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/imports/ImportMetaDataExecutorTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/imports/ImportMetaDataExecutorTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.imports;
-import com.fasterxml.jackson.core.JsonProcessingException;
+import org.apache.shardingsphere.infra.util.json.JsonException;
import org.apache.commons.codec.binary.Base64;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.authority.rule.builder.DefaultAuthorityRuleConfigurationBuilder;
@@ -114,7 +114,7 @@ class ImportMetaDataExecutorTest {
Arguments.of("import empty metadata", createImportMetaDataStatement(EMPTY_METADATA_FILE_PATH), mockContextManager(), EmptyStorageUnitException.class),
Arguments.of("import existed metadata", createImportMetaDataStatement(EMPTY_METADATA_FILE_PATH), createContextManagerWithExistedDatabase(), DatabaseCreateExistsException.class),
Arguments.of("import metadata from missing file", new ImportMetaDataStatement(null, NOT_EXIST_METADATA_FILE_PATH), mockContextManager(), FileIOException.class),
- Arguments.of("import metadata with empty file path in file branch", createStatementWithEmptyFilePathInFileBranch(), mockContextManager(), JsonProcessingException.class));
+ Arguments.of("import metadata with empty file path in file branch", createStatementWithEmptyFilePathInFileBranch(), mockContextManager(), JsonException.class));
}
private static ImportMetaDataStatement createImportMetaDataStatement(final String filePath) {
diff --git a/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/ZipkinSpanAssert.java b/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/ZipkinSpanAssert.java
index 2c691bac8b6..af37bb7a4ef 100644
--- a/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/ZipkinSpanAssert.java
+++ b/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/ZipkinSpanAssert.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.test.e2e.agent.zipkin.asserts;
-import com.fasterxml.jackson.core.type.TypeReference;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.util.json.JsonTypeReference;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
import org.apache.shardingsphere.test.e2e.agent.engine.util.AgentE2EHttpUtils;
import org.apache.shardingsphere.test.e2e.agent.zipkin.asserts.response.ZipkinSpanResponse;
@@ -75,7 +75,7 @@ public final class ZipkinSpanAssert {
@SneakyThrows(IOException.class)
private static Collection<ZipkinSpanResponse> queryTraceResponses(final ZipkinE2ETestCase expected, final String url) {
- List<List<ZipkinSpanResponse>> result = JsonUtils.fromJsonString(AgentE2EHttpUtils.query(url), new TypeReference<List<List<ZipkinSpanResponse>>>() {
+ List<List<ZipkinSpanResponse>> result = JsonUtils.fromJsonString(AgentE2EHttpUtils.query(url), new JsonTypeReference<List<List<ZipkinSpanResponse>>>() {
});
return result.stream().findFirst().orElse(Collections.emptyList()).stream().filter(each -> expected.getSpanName().equalsIgnoreCase(each.getName())).collect(Collectors.toList());
}
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/llm/conversation/LLMMCPJsonValues.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/llm/conversation/LLMMCPJsonValues.java
index 92d80600509..bfa83774f31 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/llm/conversation/LLMMCPJsonValues.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/llm/conversation/LLMMCPJsonValues.java
@@ -17,11 +17,10 @@
package org.apache.shardingsphere.test.e2e.mcp.llm.conversation;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.util.json.JsonException;
+import org.apache.shardingsphere.infra.util.json.JsonTypeReference;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
import java.util.Map;
@@ -29,13 +28,11 @@ import java.util.Map;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
final class LLMMCPJsonValues {
- private static final ObjectMapper OBJECT_MAPPER = JsonUtils.createObjectMapper();
-
static Map<String, Object> parseToolArguments(final String argumentsJson) {
try {
- return OBJECT_MAPPER.readValue(argumentsJson, new TypeReference<>() {
+ return JsonUtils.fromJsonString(argumentsJson, new JsonTypeReference<Map<String, Object>>() {
});
- } catch (final JsonProcessingException ex) {
+ } catch (final JsonException ex) {
throw new IllegalArgumentException("Invalid tool arguments JSON.", ex);
}
}
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/llm/conversation/client/LLMChatModelClient.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/llm/conversation/client/LLMChatModelClient.java
index a8100de4f45..f5fef221e3e 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/llm/conversation/client/LLMChatModelClient.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/llm/conversation/client/LLMChatModelClient.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.test.e2e.mcp.llm.conversation.client;
-import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.base.Preconditions;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.util.json.JsonTypeReference;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
import org.apache.shardingsphere.test.e2e.mcp.llm.config.LLME2EConfiguration;
@@ -233,7 +233,7 @@ public final class LLMChatModelClient {
private Map<String, Object> parseJsonObject(final String responseBody, final String errorMessage) {
try {
- return JsonUtils.fromJsonString(responseBody, new TypeReference<>() {
+ return JsonUtils.fromJsonString(responseBody, new JsonTypeReference<Map<String, Object>>() {
});
// CHECKSTYLE:OFF
} catch (final Exception ex) {
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionPayloads.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionPayloads.java
index b92da1f0c09..4c6af9e2ef0 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionPayloads.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionPayloads.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.test.e2e.mcp.support.transport;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import io.modelcontextprotocol.json.McpJsonMapper;
+import io.modelcontextprotocol.json.TypeRef;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
+import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportJsonMapperFactory;
import java.io.IOException;
import java.util.LinkedHashMap;
@@ -34,7 +34,7 @@ import java.util.Map;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MCPInteractionPayloads {
- private static final ObjectMapper OBJECT_MAPPER = JsonUtils.createObjectMapper();
+ private static final McpJsonMapper JSON_MAPPER = MCPTransportJsonMapperFactory.create();
/**
* Parse one MCP HTTP or STDIO JSON payload.
@@ -45,7 +45,7 @@ public final class MCPInteractionPayloads {
*/
public static Map<String, Object> parseJsonPayload(final String responseBody) {
try {
- return OBJECT_MAPPER.readValue(normalizeJsonBody(responseBody), new TypeReference<>() {
+ return JSON_MAPPER.readValue(normalizeJsonBody(responseBody), new TypeRef<Map<String, Object>>() {
});
} catch (final IOException ex) {
throw new IllegalStateException("Failed to parse MCP response body.", ex);
@@ -202,7 +202,7 @@ public final class MCPInteractionPayloads {
private static Map<String, Object> parseJsonText(final String value) {
try {
- return OBJECT_MAPPER.readValue(value, new TypeReference<>() {
+ return JSON_MAPPER.readValue(value, new TypeRef<Map<String, Object>>() {
});
} catch (final IOException ex) {
throw new IllegalStateException("Failed to parse MCP JSON text payload.", ex);
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionProtocolSupport.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionProtocolSupport.java
index 4e9fe46a35e..2d3bfe44723 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionProtocolSupport.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/MCPInteractionProtocolSupport.java
@@ -17,11 +17,13 @@
package org.apache.shardingsphere.test.e2e.mcp.support.transport;
+import io.modelcontextprotocol.json.McpJsonMapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import io.modelcontextprotocol.spec.ProtocolVersions;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
+import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportJsonMapperFactory;
+import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -33,6 +35,8 @@ public final class MCPInteractionProtocolSupport {
public static final String PROTOCOL_VERSION = ProtocolVersions.MCP_2025_11_25;
+ private static final McpJsonMapper JSON_MAPPER = MCPTransportJsonMapperFactory.create();
+
/**
* Create initialize request parameters for the given client name.
*
@@ -87,7 +91,7 @@ public final class MCPInteractionProtocolSupport {
* @return JSON notification body
*/
public static String createJsonRpcNotificationBody(final String method, final Map<String, Object> params) {
- return JsonUtils.toJsonString(createJsonRpcNotification(method, params));
+ return toJsonString(createJsonRpcNotification(method, params));
}
/**
@@ -99,6 +103,14 @@ public final class MCPInteractionProtocolSupport {
* @return JSON request body
*/
public static String createJsonRpcRequestBody(final String requestId, final String method, final Map<String, Object> params) {
- return JsonUtils.toJsonString(createJsonRpcRequest(requestId, method, params));
+ return toJsonString(createJsonRpcRequest(requestId, method, params));
+ }
+
+ private static String toJsonString(final Object value) {
+ try {
+ return JSON_MAPPER.writeValueAsString(value);
+ } catch (final IOException ex) {
+ throw new IllegalStateException("Failed to serialize MCP JSON-RPC payload.", ex);
+ }
}
}
diff --git a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/client/AbstractProcessMCPStdioInteractionClient.java b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/client/AbstractProcessMCPStdioInteractionClient.java
index 6b5fa398856..adbf94967b9 100644
--- a/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/client/AbstractProcessMCPStdioInteractionClient.java
+++ b/test/e2e/mcp/src/test/java/org/apache/shardingsphere/test/e2e/mcp/support/transport/client/AbstractProcessMCPStdioInteractionClient.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.test.e2e.mcp.support.transport.client;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
+import io.modelcontextprotocol.json.McpJsonMapper;
+import io.modelcontextprotocol.json.TypeRef;
+import org.apache.shardingsphere.mcp.bootstrap.transport.MCPTransportJsonMapperFactory;
import org.apache.shardingsphere.test.e2e.mcp.support.artifact.MCPArtifactUtils;
import org.apache.shardingsphere.test.e2e.mcp.support.transport.MCPInteractionPayloads;
import org.apache.shardingsphere.test.e2e.mcp.support.transport.MCPInteractionProtocolSupport;
@@ -53,7 +53,7 @@ abstract class AbstractProcessMCPStdioInteractionClient extends AbstractMCPInter
private static final String INITIALIZE_REQUEST_ID = "init-1";
- private static final ObjectMapper OBJECT_MAPPER = JsonUtils.createObjectMapper();
+ private static final McpJsonMapper JSON_MAPPER = MCPTransportJsonMapperFactory.create();
private final List<String> stdErrorMessages = new CopyOnWriteArrayList<>();
@@ -154,7 +154,7 @@ abstract class AbstractProcessMCPStdioInteractionClient extends AbstractMCPInter
}
private void writeJsonRpcMessage(final Map<String, Object> payload) throws IOException {
- writer.write(OBJECT_MAPPER.writeValueAsString(payload));
+ writer.write(JSON_MAPPER.writeValueAsString(payload));
writer.newLine();
writer.flush();
}
@@ -166,7 +166,7 @@ abstract class AbstractProcessMCPStdioInteractionClient extends AbstractMCPInter
if (line.isBlank()) {
continue;
}
- Map<String, Object> result = OBJECT_MAPPER.readValue(line, new TypeReference<>() {
+ Map<String, Object> result = JSON_MAPPER.readValue(line, new TypeRef<>() {
});
if (requestId.equals(String.valueOf(result.get("id")))) {
return result;
diff --git a/test/it/parser/pom.xml b/test/it/parser/pom.xml
index 85f9d982af3..aefd0e1e87b 100644
--- a/test/it/parser/pom.xml
+++ b/test/it/parser/pom.xml
@@ -203,9 +203,5 @@
<artifactId>commons-csv</artifactId>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- </dependency>
</dependencies>
</project>
diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/external/loader/strategy/type/GitHubTestParameterLoadStrategy.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/external/loader/strategy/type/GitHubTestParameterLoadStrategy.java
index 05c8589b252..c895bc1abd3 100644
--- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/external/loader/strategy/type/GitHubTestParameterLoadStrategy.java
+++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/external/loader/strategy/type/GitHubTestParameterLoadStrategy.java
@@ -17,9 +17,6 @@
package org.apache.shardingsphere.test.it.sql.parser.external.loader.strategy.type;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
@@ -35,6 +32,7 @@ import java.net.URLConnection;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
+import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -44,8 +42,6 @@ public final class GitHubTestParameterLoadStrategy implements ExternalTestParame
private static final String TOKEN_KEY = "it.github.token";
- private static final ObjectMapper JSON_MAPPER = JsonUtils.createObjectMapper();
-
@Override
public Collection<FileSummary> loadSQLCaseFileSummaries(final URI uri) {
if (uri.toString().isEmpty()) {
@@ -55,21 +51,16 @@ public final class GitHubTestParameterLoadStrategy implements ExternalTestParame
if (content.isEmpty()) {
return Collections.emptyList();
}
- JsonNode rootNode = parseContent(content);
- return rootNode.isArray() ? getFileSummariesByArray(rootNode) : getFileSummaries(rootNode);
- }
-
- @SneakyThrows(JsonProcessingException.class)
- private JsonNode parseContent(final String content) {
- return JSON_MAPPER.readTree(content);
+ Object rootNode = JsonUtils.fromJsonString(content, Object.class);
+ return rootNode instanceof Collection ? getFileSummariesByArray((Collection<?>) rootNode) : getFileSummaries((Map<?, ?>) rootNode);
}
- private Collection<FileSummary> getFileSummaries(final JsonNode rootNode) {
+ private Collection<FileSummary> getFileSummaries(final Map<?, ?> rootNode) {
Collection<FileSummary> result = new LinkedList<>();
- String fileName = rootNode.get("name").textValue();
- String folderType = rootNode.get("type").textValue();
- String downloadURL = rootNode.get("download_url").textValue();
- String htmlURL = rootNode.get("html_url").textValue();
+ String fileName = (String) rootNode.get("name");
+ String folderType = (String) rootNode.get("type");
+ String downloadURL = (String) rootNode.get("download_url");
+ String htmlURL = (String) rootNode.get("html_url");
if ("file".equals(folderType)) {
result.add(new FileSummary(fileName, downloadURL));
} else if ("dir".equals(folderType)) {
@@ -78,10 +69,10 @@ public final class GitHubTestParameterLoadStrategy implements ExternalTestParame
return result;
}
- private Collection<FileSummary> getFileSummariesByArray(final JsonNode rootNode) {
+ private Collection<FileSummary> getFileSummariesByArray(final Collection<?> rootNode) {
Collection<FileSummary> result = new LinkedList<>();
- for (JsonNode each : rootNode) {
- result.addAll(getFileSummaries(each));
+ for (Object each : rootNode) {
+ result.addAll(getFileSummaries((Map<?, ?>) each));
}
return result;
}