2121 */
2222
2323import com .fasterxml .jackson .databind .JsonNode ;
24- import com .fasterxml .jackson .databind .ObjectMapper ;
2524import com .fasterxml .jackson .databind .node .ObjectNode ;
2625
26+ import org .springframework .ai .util .json .JsonParser ;
2727import org .springframework .util .Assert ;
2828
2929/**
3030 * Utility class for converting JSON Schema to OpenAPI schema format.
3131 */
3232public final class JsonSchemaConverter {
3333
34- private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
35-
3634 private JsonSchemaConverter () {
3735 // Prevent instantiation
3836 }
3937
4038 public static ObjectNode fromJson (String jsonString ) {
4139 try {
42- return (ObjectNode ) OBJECT_MAPPER .readTree (jsonString );
40+ return (ObjectNode ) JsonParser . getObjectMapper () .readTree (jsonString );
4341 }
4442 catch (Exception e ) {
4543 throw new RuntimeException ("Failed to parse JSON: " + jsonString , e );
@@ -57,7 +55,7 @@ public static ObjectNode convertToOpenApiSchema(ObjectNode jsonSchemaNode) {
5755
5856 try {
5957 // Convert to OpenAPI schema using our custom conversion logic
60- ObjectNode openApiSchema = convertSchema (jsonSchemaNode , OBJECT_MAPPER .getNodeFactory ());
58+ ObjectNode openApiSchema = convertSchema (jsonSchemaNode , JsonParser . getObjectMapper () .getNodeFactory ());
6159
6260 // Add OpenAPI-specific metadata
6361 if (!openApiSchema .has ("openapi" )) {
@@ -105,8 +103,8 @@ private static void handleJsonSchemaSpecifics(ObjectNode source, ObjectNode targ
105103 ObjectNode properties = target .putObject ("properties" );
106104 source .get ("properties" ).fields ().forEachRemaining (entry -> {
107105 if (entry .getValue () instanceof ObjectNode ) {
108- properties .set (entry .getKey (),
109- convertSchema (( ObjectNode ) entry . getValue (), OBJECT_MAPPER .getNodeFactory ()));
106+ properties .set (entry .getKey (), convertSchema (( ObjectNode ) entry . getValue (),
107+ JsonParser . getObjectMapper () .getNodeFactory ()));
110108 }
111109 });
112110 }
@@ -124,15 +122,15 @@ private static void handleJsonSchemaSpecifics(ObjectNode source, ObjectNode targ
124122 }
125123 else if (additionalProps .isObject ()) {
126124 target .set ("additionalProperties" ,
127- convertSchema ((ObjectNode ) additionalProps , OBJECT_MAPPER .getNodeFactory ()));
125+ convertSchema ((ObjectNode ) additionalProps , JsonParser . getObjectMapper () .getNodeFactory ()));
128126 }
129127 }
130128
131129 // Handle arrays
132130 if (source .has ("items" )) {
133131 JsonNode items = source .get ("items" );
134132 if (items .isObject ()) {
135- target .set ("items" , convertSchema ((ObjectNode ) items , OBJECT_MAPPER .getNodeFactory ()));
133+ target .set ("items" , convertSchema ((ObjectNode ) items , JsonParser . getObjectMapper () .getNodeFactory ()));
136134 }
137135 }
138136
0 commit comments