Skip to content

Conversation

@zoewangg
Copy link
Contributor

@zoewangg zoewangg commented Apr 1, 2021

Description

Added a new attribute-level annotation that initializes a class as empty class if all fields are null when mapping a DynamoDb record to a Java bean

Motivation and Context

#2280 #2334

Testing

Added unit tests

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the CHANGELOG
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@zoewangg zoewangg changed the title DynamodbEnhanced client preserve empty bean support DynamodbEnhanced client add preserve empty bean support Apr 1, 2021
this.buildItemFunction = builder.buildItemFunction;
this.tableMetadata = tableMetadataBuilder.build();
this.itemType = EnhancedType.of(builder.itemClass);
this.preserveEmtpyBean = builder.itemClass.getAnnotation(DynamoDbPreserveEmptyBean.class) != null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static*TableSchema must not perform any reflection. It must be statically configurable from its builder using properties and tags. We could achieve this by having a boolean builder property for example like

   .preserveEmptyBean(true)

and then BeanTableSchema and ImmutableTableSchema would scan for the annotation and add that flag to the StaticImmutableTableSchema they were building.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was not aware of this. I'll see if I can add a checkstyle for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more of a design thing than a technical limitation. StaticTableSchema and StaticImmutableTableSchema are both public classes (APIs) that customers that specifically do not want to use reflection can opt to use to construct their TableSchema instances without any runtime class metadata being involved. We wouldn't want to break that contract/promise.

@zoewangg zoewangg force-pushed the zoewang/preserveEmptyBean branch from 2044b11 to 5593b48 Compare April 6, 2021 01:24
@cenedhryn cenedhryn self-requested a review April 6, 2021 20:57
@zoewangg zoewangg force-pushed the zoewang/preserveEmptyBean branch from a77e3ef to 8ae5081 Compare April 7, 2021 04:00
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice with a comprehensive example!

…ass if all fields are null when mapping a DynamoDb record to a Java bean
Comment on lines +180 to +183
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful!

@zoewangg zoewangg force-pushed the zoewang/preserveEmptyBean branch from cfbee38 to f2a0a69 Compare April 8, 2021 18:17
@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 8, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants