|
11 | 11 | import java.util.List; |
12 | 12 | import java.util.Map; |
13 | 13 |
|
14 | | -import io.modelcontextprotocol.json.TypeRef; |
15 | 14 | import io.modelcontextprotocol.spec.McpSchema.TextResourceContents; |
16 | 15 | import net.javacrumbs.jsonunit.core.Option; |
17 | 16 | import org.assertj.core.api.InstanceOfAssertFactories; |
@@ -765,22 +764,11 @@ void testJsonSchema() throws Exception { |
765 | 764 | } |
766 | 765 | """; |
767 | 766 |
|
768 | | - // Deserialize the original string to a JsonSchema object |
769 | | - Map<String, Object> schema = JSON_MAPPER.readValue(schemaJson, new TypeRef<HashMap<String, Object>>() { |
770 | | - }); |
771 | | - |
772 | | - // Serialize the object back to a string |
773 | | - String serialized = JSON_MAPPER.writeValueAsString(schema); |
774 | | - |
775 | | - // Deserialize again |
776 | | - Map<String, Object> deserialized = JSON_MAPPER.readValue(serialized, new TypeRef<HashMap<String, Object>>() { |
777 | | - }); |
778 | | - |
779 | | - // Serialize one more time and compare with the first serialization |
780 | | - String serializedAgain = JSON_MAPPER.writeValueAsString(deserialized); |
| 767 | + McpSchema.Tool tool = JSON_MAPPER.readValue(""" |
| 768 | + {"name": "addressTool", "inputSchema": %s} |
| 769 | + """.formatted(schemaJson), McpSchema.Tool.class); |
781 | 770 |
|
782 | | - // The two serialized strings should be the same |
783 | | - assertThatJson(serializedAgain).when(Option.IGNORING_ARRAY_ORDER).isEqualTo(json(serialized)); |
| 771 | + assertThatJson(JSON_MAPPER.writeValueAsString(tool)).inPath("$.inputSchema").isEqualTo(json(schemaJson)); |
784 | 772 | } |
785 | 773 |
|
786 | 774 | @Test |
@@ -810,22 +798,11 @@ void testJsonSchemaWithDefinitions() throws Exception { |
810 | 798 | } |
811 | 799 | """; |
812 | 800 |
|
813 | | - // Deserialize the original string to a JsonSchema object |
814 | | - Map<String, Object> schema = JSON_MAPPER.readValue(schemaJson, new TypeRef<HashMap<String, Object>>() { |
815 | | - }); |
816 | | - |
817 | | - // Serialize the object back to a string |
818 | | - String serialized = JSON_MAPPER.writeValueAsString(schema); |
819 | | - |
820 | | - // Deserialize again |
821 | | - Map<String, Object> deserialized = JSON_MAPPER.readValue(serialized, new TypeRef<HashMap<String, Object>>() { |
822 | | - }); |
823 | | - |
824 | | - // Serialize one more time and compare with the first serialization |
825 | | - String serializedAgain = JSON_MAPPER.writeValueAsString(deserialized); |
| 801 | + McpSchema.Tool tool = JSON_MAPPER.readValue(""" |
| 802 | + {"name": "addressTool", "inputSchema": %s} |
| 803 | + """.formatted(schemaJson), McpSchema.Tool.class); |
826 | 804 |
|
827 | | - // The two serialized strings should be the same |
828 | | - assertThatJson(serializedAgain).when(Option.IGNORING_ARRAY_ORDER).isEqualTo(json(serialized)); |
| 805 | + assertThatJson(JSON_MAPPER.writeValueAsString(tool)).inPath("$.inputSchema").isEqualTo(json(schemaJson)); |
829 | 806 | } |
830 | 807 |
|
831 | 808 | @Test |
@@ -922,10 +899,9 @@ void testToolWithMeta() throws Exception { |
922 | 899 | } |
923 | 900 | """; |
924 | 901 |
|
925 | | - Map<String, Object> inputSchema = Map.of("inputSchema", schemaJson); |
926 | 902 | Map<String, Object> meta = Map.of("metaKey", "metaValue"); |
927 | 903 |
|
928 | | - McpSchema.Tool tool = McpSchema.Tool.builder("addressTool", inputSchema) |
| 904 | + McpSchema.Tool tool = McpSchema.Tool.builder("addressTool", JSON_MAPPER, schemaJson) |
929 | 905 | .title("addressTool") |
930 | 906 | .description("Handles addresses") |
931 | 907 | .meta(meta) |
|
0 commit comments