Skip to content

Commit f9c673d

Browse files
committed
Fixed DynamoDbEnhancedClient TableSchema::itemToMap to handle flattened members when ignoreNulls is false
1 parent b1b5216 commit f9c673d

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "Amazon DynamoDB Enhanced Client",
4+
"contributor": "",
5+
"description": "Fixed DynamoDbEnhancedClient TableSchema::itemToMap to return a map that contains a consistent representation of null top-level (non-flattened) attributes and flattened attributes when their enclosing member is null and ignoreNulls is set to false."
6+
}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#### 👋 _Looking for changelogs for older versions? You can find them in the [changelogs](./changelogs) directory._
2+
# __2.30.8__ __2025-01-28__
3+
## __Amazon DynamoDB Enhanced Client__
4+
- ### Bugfixes
5+
- Fixed DynamoDbEnhancedClient TableSchema::itemToMap doesn't respect ignoreNulls with null @DynamoDbFlattened members. See [#2540](https://github.com/aws/aws-sdk-java-v2/issues/2540)
6+
27
# __2.30.7__ __2025-01-27__
38
## __AWS Elemental MediaConvert__
49
- ### Features

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticImmutableTableSchema.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private B mapToItem(B thisBuilder,
126126
private Map<String, AttributeValue> itemToMap(T item, boolean ignoreNulls) {
127127
T1 otherItem = this.otherItemGetter.apply(item);
128128

129-
if (otherItem == null) {
129+
if (otherItem == null && ignoreNulls) {
130130
return Collections.emptyMap();
131131
}
132132

@@ -515,7 +515,9 @@ public Map<String, AttributeValue> itemToMap(T item, boolean ignoreNulls) {
515515

516516
attributeMappers.forEach(attributeMapper -> {
517517
String attributeKey = attributeMapper.attributeName();
518-
AttributeValue attributeValue = attributeMapper.attributeGetterMethod().apply(item);
518+
AttributeValue attributeValue = item == null ?
519+
AttributeValue.fromNul(true) :
520+
attributeMapper.attributeGetterMethod().apply(item);
519521

520522
if (!ignoreNulls || !isNullAttributeValue(attributeValue)) {
521523
attributeValueMap.put(attributeKey, attributeValue);

services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticImmutableTableSchemaTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,11 @@ public void buildAbstractWithFlatten() {
13861386

13871387
assertThat(tableSchema.itemToMap(item, true),
13881388
is(singletonMap("documentString", AttributeValue.builder().s("test-string").build())));
1389+
1390+
Map<String, AttributeValue> attributeMapWithNulls = tableSchema.itemToMap(item, false);
1391+
assertThat(attributeMapWithNulls.size(), is(2));
1392+
assertThat(attributeMapWithNulls, hasEntry("documentString", AttributeValue.builder().s("test-string").build()));
1393+
assertThat(attributeMapWithNulls, hasEntry("documentInteger", AttributeValue.fromNul(true)));
13891394
}
13901395

13911396
@Test

0 commit comments

Comments
 (0)