Skip to content
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

Fixed DynamoDbEnhancedClient TableSchema::itemToMap to handle flatten… #5832

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "Amazon DynamoDB Enhanced Client",
"contributor": "",
"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."
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#### 👋 _Looking for changelogs for older versions? You can find them in the [changelogs](./changelogs) directory._
# __2.30.10__ __2025-01-30__
## __Amazon DynamoDB Enhanced Client__
- ### Bugfixes
- Fixed DynamoDbEnhancedClient TableSchema::itemToMap doesn't respect ignoreNulls with null @DynamoDbFlattened members. See [#2540](https://github.com/aws/aws-sdk-java-v2/issues/2540)

# __2.30.9__ __2025-01-29__
## __AWS Billing and Cost Management Pricing Calculator__
- ### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private B mapToItem(B thisBuilder,
private Map<String, AttributeValue> itemToMap(T item, boolean ignoreNulls) {
T1 otherItem = this.otherItemGetter.apply(item);

if (otherItem == null) {
if (otherItem == null && ignoreNulls) {
return Collections.emptyMap();
}

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

attributeMappers.forEach(attributeMapper -> {
String attributeKey = attributeMapper.attributeName();
AttributeValue attributeValue = attributeMapper.attributeGetterMethod().apply(item);
AttributeValue attributeValue = item == null ?
AttributeValue.fromNul(true) :
attributeMapper.attributeGetterMethod().apply(item);

if (!ignoreNulls || !isNullAttributeValue(attributeValue)) {
attributeValueMap.put(attributeKey, attributeValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,11 @@ public void buildAbstractWithFlatten() {

assertThat(tableSchema.itemToMap(item, true),
is(singletonMap("documentString", AttributeValue.builder().s("test-string").build())));

Map<String, AttributeValue> attributeMapWithNulls = tableSchema.itemToMap(item, false);
assertThat(attributeMapWithNulls.size(), is(2));
assertThat(attributeMapWithNulls, hasEntry("documentString", AttributeValue.builder().s("test-string").build()));
assertThat(attributeMapWithNulls, hasEntry("documentInteger", AttributeValue.fromNul(true)));
}

@Test
Expand Down