19
19
20
20
import com .fasterxml .jackson .databind .DeserializationFeature ;
21
21
import com .fasterxml .jackson .databind .ObjectMapper ;
22
+ import com .fasterxml .jackson .databind .SerializationFeature ;
23
+ import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
22
24
23
25
import org .springframework .ai .model .ModelOptionsUtils ;
24
26
import org .springframework .util .Assert ;
@@ -35,9 +37,8 @@ public class FunctionCallbackWrapper<I, O> extends AbstractFunctionCallback<I, O
35
37
private final Function <I , O > function ;
36
38
37
39
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 );
41
42
Assert .notNull (function , "Function must not be null" );
42
43
this .function = function ;
43
44
}
@@ -85,7 +86,9 @@ public Builder(Function<I, O> function) {
85
86
private String inputTypeSchema ;
86
87
87
88
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 ());
89
92
90
93
public Builder <I , O > withName (String name ) {
91
94
Assert .hasText (name , "Name must not be empty" );
@@ -133,7 +136,6 @@ public FunctionCallbackWrapper<I, O> build() {
133
136
134
137
Assert .hasText (this .name , "Name must not be empty" );
135
138
Assert .hasText (this .description , "Description must not be empty" );
136
- // Assert.notNull(this.inputType, "InputType must not be null");
137
139
Assert .notNull (this .function , "Function must not be null" );
138
140
Assert .notNull (this .responseConverter , "ResponseConverter must not be null" );
139
141
Assert .notNull (this .objectMapper , "ObjectMapper must not be null" );
@@ -148,7 +150,7 @@ public FunctionCallbackWrapper<I, O> build() {
148
150
}
149
151
150
152
return new FunctionCallbackWrapper <>(this .name , this .description , this .inputTypeSchema , this .inputType ,
151
- this .responseConverter , this .function );
153
+ this .responseConverter , this .objectMapper , this . function );
152
154
}
153
155
154
156
}
0 commit comments