Skip to content

Commit 50e0d55

Browse files
committed
Updated Null check in the conveter itself while iterating Arrays of AttributeValue
1 parent a5ae056 commit 50e0d55

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/internal/unmarshall/document/DocumentUnmarshaller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public Document visitString(String string) {
5050
@Override
5151
public Document visitArray(List<JsonNode> array) {
5252
return Document.fromList(array.stream()
53-
.map(node -> node == null ? Document.fromNull() : node.visit(this))
53+
.map(node -> node.visit(this))
5454
.collect(Collectors.toList()));
5555
}
5656

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/document/EnhancedDocument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ interface Builder {
449449
Builder addJson(String attributeName, String json);
450450

451451
/**
452-
* Appends an attribute of name attributeName with specified value of the give EnhancedDocument.
452+
* Appends an attribute of name attributeName with specified value of the given EnhancedDocument.
453453
* @param attributeName Name of the attribute that needs to be added in the Document.
454454
* @param enhancedDocument that needs to be added as a value to a key attribute.
455455
* @return Builder instance to construct a {@link EnhancedDocument}

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/JsonItemAttributeConverter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public AttributeValueType attributeValueType() {
6767

6868
@Override
6969
public AttributeValue transformFrom(JsonNode input) {
70-
JsonNodeToAttributeValueMapConvertor jsonNodeToAttributeValueMapConvertor = new JsonNodeToAttributeValueMapConvertor();
71-
return input.visit(jsonNodeToAttributeValueMapConvertor);
70+
JsonNodeToAttributeValueMapConverter attributeValueMapConverter = JsonNodeToAttributeValueMapConverter.instance();
71+
return input.visit(attributeValueMapConverter);
7272
}
7373

7474
@Override
@@ -132,8 +132,10 @@ public JsonNode convertSetOfBytes(List<SdkBytes> value) {
132132
@Override
133133
public JsonNode convertListOfAttributeValues(List<AttributeValue> value) {
134134
return new ArrayJsonNode(value.stream().map(
135-
attributeValue -> EnhancedAttributeValue.fromAttributeValue(
136-
attributeValue).convert(VISITOR)).collect(Collectors.toList()));
135+
attributeValue -> {
136+
EnhancedAttributeValue enhancedAttributeValue = EnhancedAttributeValue.fromAttributeValue(attributeValue);
137+
return enhancedAttributeValue.isNull() ? NullJsonNode.instance() : enhancedAttributeValue.convert(VISITOR);
138+
}).collect(Collectors.toList()));
137139

138140
}
139141
}
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@
2525
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
2626

2727
@SdkInternalApi
28-
public class JsonNodeToAttributeValueMapConvertor implements JsonNodeVisitor<AttributeValue> {
28+
public class JsonNodeToAttributeValueMapConverter implements JsonNodeVisitor<AttributeValue> {
29+
30+
private JsonNodeToAttributeValueMapConverter(){
31+
}
32+
33+
private static JsonNodeToAttributeValueMapConverter INSTANCE = new JsonNodeToAttributeValueMapConverter();
34+
35+
public static JsonNodeToAttributeValueMapConverter instance(){
36+
return INSTANCE;
37+
}
38+
39+
40+
2941
@Override
3042
public AttributeValue visitNull() {
3143
return AttributeValue.builder().build();

0 commit comments

Comments
 (0)