From 0a3a2022a85eca12023c2c844ec0470fc78c1da7 Mon Sep 17 00:00:00 2001 From: Fu Cheng Date: Mon, 8 Apr 2024 15:23:57 +0800 Subject: [PATCH] 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. --- .../ai/model/function/FunctionCallbackWrapper.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java index dbf28dd8b..d065a5fe4 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java @@ -19,6 +19,8 @@ import java.util.function.Function; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.springframework.ai.model.ModelOptionsUtils; import org.springframework.util.Assert; @@ -35,9 +37,8 @@ public class FunctionCallbackWrapper extends AbstractFunctionCallback function; private FunctionCallbackWrapper(String name, String description, String inputTypeSchema, Class inputType, - Function responseConverter, Function function) { - super(name, description, inputTypeSchema, inputType, responseConverter, - new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)); + Function responseConverter, ObjectMapper objectMapper, Function function) { + super(name, description, inputTypeSchema, inputType, responseConverter, objectMapper); Assert.notNull(function, "Function must not be null"); this.function = function; } @@ -85,7 +86,9 @@ public class FunctionCallbackWrapper extends AbstractFunctionCallback withName(String name) { Assert.hasText(name, "Name must not be empty"); @@ -133,7 +136,6 @@ public class FunctionCallbackWrapper extends AbstractFunctionCallback extends AbstractFunctionCallback(this.name, this.description, this.inputTypeSchema, this.inputType, - this.responseConverter, this.function); + this.responseConverter, this.objectMapper, this.function); } }