Skip to content

Commit 9074823

Browse files
authored
Allow serializing null properties for Bedrock (#3607)
Fixes #3600
1 parent 0b88586 commit 9074823

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

langchain4j-bedrock/src/main/java/dev/langchain4j/model/bedrock/AwsDocumentConverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class AwsDocumentConverter {
2323

2424
static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
2525
.disable(INDENT_OUTPUT)
26-
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
27-
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
26+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
2827

2928
private AwsDocumentConverter() {}
3029

@@ -55,6 +54,8 @@ private static Object documentToObject(Document doc) {
5554
Map<String, Object> innerObject = new HashMap<>();
5655
doc.asMap().forEach((k, v) -> innerObject.put(k, documentToObject(v)));
5756
return innerObject;
57+
} else if (doc.isNull()) {
58+
return null;
5859
} else {
5960
return doc.asString();
6061
}

langchain4j-bedrock/src/test/java/dev/langchain4j/model/bedrock/AwsDocumentConverterTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void convert_primitive_types_to_json() {
2222
docMap.put("integer", Document.fromNumber(42));
2323
docMap.put("double", Document.fromNumber(42.5));
2424
docMap.put("boolean", Document.fromBoolean(true));
25+
docMap.put("null", Document.fromNull());
2526
Document document = Document.fromMap(docMap);
2627

2728
// When
@@ -32,7 +33,8 @@ void convert_primitive_types_to_json() {
3233
.containsIgnoringWhitespaces("\"string\": \"test\"")
3334
.containsIgnoringWhitespaces("\"integer\": 42")
3435
.containsIgnoringWhitespaces("\"double\": 42.5")
35-
.containsIgnoringWhitespaces("\"boolean\": true");
36+
.containsIgnoringWhitespaces("\"boolean\": true")
37+
.containsIgnoringWhitespaces("\"null\": null");
3638
}
3739

3840
@Test

0 commit comments

Comments
 (0)