-
Notifications
You must be signed in to change notification settings - Fork 976
Fixed DynamoDbEnhancedClient TableSchema::itemToMap to handle null fl… #6137
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
base: master
Are you sure you want to change the base?
Fixed DynamoDbEnhancedClient TableSchema::itemToMap to handle null fl… #6137
Conversation
…attened members when ignoreNulls is false
020dacd to
f95780f
Compare
…l-flattened-members
| if (item != null) { | ||
| attributeValueMap.putAll(flattenedMapper.itemToMap(item, ignoreNulls)); | ||
| } else if (!ignoreNulls) { | ||
| attributeValueMap.put(name, AttributeValue.fromNul(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the right behavior ? Here name is an attribute name from the flattened object, not the flattened field name itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the behavior is correct. The whole idea with the flattened is to bring the attributes from all the flattened members to root in the returned map, as like they belong to the parent root level. The flattened fields themself containing those attributes will actually not be visible in the DynamoDb table.
|
|
||
| flattenedObjectMappers.forEach((name, flattenedMapper) -> { | ||
| attributeValueMap.putAll(flattenedMapper.itemToMap(item, ignoreNulls)); | ||
| if (item != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also when item != null, the same flattenedMapper.itemToMap() is called multiple times for the same flattened object. Is my understanding correct?
Can we add this so it loops just once for every flattenMapper?
if (processedMappers.add(flattenedMapper)) {
attributeValueMap.putAll(flattenedMapper.itemToMap(item, ignoreNulls));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I updated the PR with this improvement.
Fixed [DynamoDbEnhancedClient]
TableSchema::itemToMapdoesn't respect ignoreNulls with null@DynamoDbFlattenedmembers #2540.Description
Current behavior:
TableSchema.fromBean(Bean.class).itemToMap(bean, false)returns a map without members of any @DynamoDbFlatten'd members if the flattened member is null even though ignoreNulls is set to false.Expected behavior:
TableSchema::itemToMapshould return a map that contains a consistent representation of null top-level (non-flattened) attributes and flattened attributes when their "parent" member is null and ignoreNulls is set to false.Motivation and Context
#2540
Modifications
Updated the
StaticImmutableTableSchema -> Map<String, AttributeValue> itemToMap(T item, boolean ignoreNulls)logic to properly account for the ignoreNulls check and generateAttributeValue.fromNul(true)values for attributes of@DynamoDbFlattenedmembers that are null.Testing
The changes have already been tested by running the existing tests and also added new unit tests for the fixed behavior.
Test Coverage Checklist
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License