Skip to content

Commit b7fd600

Browse files
committed
feat: Eliminate one deserialization step in the majority of scenarios when parsing Model response
Signed-off-by: bourne7 <[email protected]>
1 parent 1256eaf commit b7fd600

File tree

1 file changed

+15
-2
lines changed
  • spring-ai-model/src/main/java/org/springframework/ai/util/json

1 file changed

+15
-2
lines changed

spring-ai-model/src/main/java/org/springframework/ai/util/json/JsonParser.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,21 @@ else if (javaType.isEnum()) {
168168
return Enum.valueOf((Class<Enum>) javaType, value.toString());
169169
}
170170

171-
String json = JsonParser.toJson(value);
172-
return JsonParser.fromJson(json, javaType);
171+
Object result = null;
172+
if (value instanceof String jsonString) {
173+
try {
174+
result = JsonParser.fromJson(jsonString, javaType);
175+
} catch (Exception e) {
176+
// ignore
177+
}
178+
}
179+
180+
if (result == null) {
181+
String json = JsonParser.toJson(value);
182+
result = JsonParser.fromJson(json, javaType);
183+
}
184+
185+
return result;
173186
}
174187

175188
}

0 commit comments

Comments
 (0)