Skip to content

DynamodbAttributeValueTransformer v1 and v2 return empty list instead of null for empty list attribute #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.amazonaws.services.dynamodbv2.model.AttributeValue;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -40,7 +41,7 @@ public static AttributeValue toAttributeValueV1(final com.amazonaws.services.lam
} else if (Objects.nonNull(value.getL())) {
return new AttributeValue()
.withL(value.getL().isEmpty()
? null
? Collections.emptyList()
: value.getL().stream()
.map(DynamodbAttributeValueTransformer::toAttributeValueV1)
.collect(Collectors.toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -52,7 +53,7 @@ public static AttributeValue toAttributeValueV2(final com.amazonaws.services.lam
} else if (Objects.nonNull(value.getL())) {
return AttributeValue.builder()
.l(value.getL().isEmpty()
? null
? Collections.emptyList()
: value.getL().stream()
.map(DynamodbAttributeValueTransformer::toAttributeValueV2)
.collect(Collectors.toList()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void testToAttributeValueV1_EmptyV1ObjectWhenEmpty_BS() {
@Test
public void testToAttributeValueV1_EmptyV1ObjectWhenEmpty_L() {
com.amazonaws.services.dynamodbv2.model.AttributeValue expectedAttributeValue_v1 =
new com.amazonaws.services.dynamodbv2.model.AttributeValue();
new com.amazonaws.services.dynamodbv2.model.AttributeValue().withL(Collections.emptyList());
Assertions.assertEquals(expectedAttributeValue_v1,
DynamodbAttributeValueTransformer.toAttributeValueV1(new AttributeValue().withL()));
Assertions.assertEquals(expectedAttributeValue_v1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void testToAttributeValueV2_EmptyV2ObjectWhenEmpty_BS() {
@Test
public void testToAttributeValueV2_EmptyV2ObjectWhenEmpty_L() {
software.amazon.awssdk.services.dynamodb.model.AttributeValue expectedAttributeValue_v2 =
software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().build();
software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().l(Collections.emptyList()).build();
Assertions.assertEquals(expectedAttributeValue_v2,
DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withL()));
Assertions.assertEquals(expectedAttributeValue_v2,
Expand Down