diff --git a/mcp-test/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java b/mcp-test/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java index ab9bc8643..29ac3a19a 100644 --- a/mcp-test/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java +++ b/mcp-test/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.Map; -import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpSchema.TextResourceContents; import net.javacrumbs.jsonunit.core.Option; import org.assertj.core.api.InstanceOfAssertFactories; @@ -765,22 +764,11 @@ void testJsonSchema() throws Exception { } """; - // Deserialize the original string to a JsonSchema object - Map schema = JSON_MAPPER.readValue(schemaJson, new TypeRef>() { - }); - - // Serialize the object back to a string - String serialized = JSON_MAPPER.writeValueAsString(schema); - - // Deserialize again - Map deserialized = JSON_MAPPER.readValue(serialized, new TypeRef>() { - }); - - // Serialize one more time and compare with the first serialization - String serializedAgain = JSON_MAPPER.writeValueAsString(deserialized); + McpSchema.Tool tool = JSON_MAPPER.readValue(""" + {"name": "addressTool", "inputSchema": %s} + """.formatted(schemaJson), McpSchema.Tool.class); - // The two serialized strings should be the same - assertThatJson(serializedAgain).when(Option.IGNORING_ARRAY_ORDER).isEqualTo(json(serialized)); + assertThatJson(JSON_MAPPER.writeValueAsString(tool)).inPath("$.inputSchema").isEqualTo(json(schemaJson)); } @Test @@ -810,22 +798,11 @@ void testJsonSchemaWithDefinitions() throws Exception { } """; - // Deserialize the original string to a JsonSchema object - Map schema = JSON_MAPPER.readValue(schemaJson, new TypeRef>() { - }); - - // Serialize the object back to a string - String serialized = JSON_MAPPER.writeValueAsString(schema); - - // Deserialize again - Map deserialized = JSON_MAPPER.readValue(serialized, new TypeRef>() { - }); - - // Serialize one more time and compare with the first serialization - String serializedAgain = JSON_MAPPER.writeValueAsString(deserialized); + McpSchema.Tool tool = JSON_MAPPER.readValue(""" + {"name": "addressTool", "inputSchema": %s} + """.formatted(schemaJson), McpSchema.Tool.class); - // The two serialized strings should be the same - assertThatJson(serializedAgain).when(Option.IGNORING_ARRAY_ORDER).isEqualTo(json(serialized)); + assertThatJson(JSON_MAPPER.writeValueAsString(tool)).inPath("$.inputSchema").isEqualTo(json(schemaJson)); } @Test @@ -922,10 +899,9 @@ void testToolWithMeta() throws Exception { } """; - Map inputSchema = Map.of("inputSchema", schemaJson); Map meta = Map.of("metaKey", "metaValue"); - McpSchema.Tool tool = McpSchema.Tool.builder("addressTool", inputSchema) + McpSchema.Tool tool = McpSchema.Tool.builder("addressTool", JSON_MAPPER, schemaJson) .title("addressTool") .description("Handles addresses") .meta(meta)