Skip to content

Commit 0a3a202

Browse files
alexcheng1982tzolov
authored andcommitted
Add ObjectMapper in FunctionCallbackWrapper constructor
- This allows custom ObjectMappers to be used when creating FunctionCallbackWrappers. - Set the FunctionCallbackWrapper#ObjectMapper default to match the ModelOptionUtils#ObjectMapper config.
1 parent 70e57a7 commit 0a3a202

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import com.fasterxml.jackson.databind.DeserializationFeature;
2121
import com.fasterxml.jackson.databind.ObjectMapper;
22+
import com.fasterxml.jackson.databind.SerializationFeature;
23+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
2224

2325
import org.springframework.ai.model.ModelOptionsUtils;
2426
import org.springframework.util.Assert;
@@ -35,9 +37,8 @@ public class FunctionCallbackWrapper<I, O> extends AbstractFunctionCallback<I, O
3537
private final Function<I, O> function;
3638

3739
private FunctionCallbackWrapper(String name, String description, String inputTypeSchema, Class<I> inputType,
38-
Function<O, String> responseConverter, Function<I, O> function) {
39-
super(name, description, inputTypeSchema, inputType, responseConverter,
40-
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false));
40+
Function<O, String> responseConverter, ObjectMapper objectMapper, Function<I, O> function) {
41+
super(name, description, inputTypeSchema, inputType, responseConverter, objectMapper);
4142
Assert.notNull(function, "Function must not be null");
4243
this.function = function;
4344
}
@@ -85,7 +86,9 @@ public Builder(Function<I, O> function) {
8586
private String inputTypeSchema;
8687

8788
private ObjectMapper objectMapper = new ObjectMapper()
88-
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
89+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
90+
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
91+
.registerModule(new JavaTimeModule());
8992

9093
public Builder<I, O> withName(String name) {
9194
Assert.hasText(name, "Name must not be empty");
@@ -133,7 +136,6 @@ public FunctionCallbackWrapper<I, O> build() {
133136

134137
Assert.hasText(this.name, "Name must not be empty");
135138
Assert.hasText(this.description, "Description must not be empty");
136-
// Assert.notNull(this.inputType, "InputType must not be null");
137139
Assert.notNull(this.function, "Function must not be null");
138140
Assert.notNull(this.responseConverter, "ResponseConverter must not be null");
139141
Assert.notNull(this.objectMapper, "ObjectMapper must not be null");
@@ -148,7 +150,7 @@ public FunctionCallbackWrapper<I, O> build() {
148150
}
149151

150152
return new FunctionCallbackWrapper<>(this.name, this.description, this.inputTypeSchema, this.inputType,
151-
this.responseConverter, this.function);
153+
this.responseConverter, this.objectMapper, this.function);
152154
}
153155

154156
}

0 commit comments

Comments
 (0)