Enhanced DynamoDB annotations are incompatible with Lombok
See original GitHub issueDescribe the Feature
Lombok is a popular system for reducing boilerplate code, especially in data-centric objects such as database entries. By annotating the class and/or member variables, it autogenerates setters and getters. This creates problems with enhanced dynamodb, because the annotations such as DynamoDbAttribute and DynamoDbPartitionKey cannot be applied to member variables, only to setter/getter functions, and the setter/getter function is not present in the source code. In DynamoDbMapper (from AWS SDK v1), annotations could be applied to functions or member variables, so Lombok worked well. It would be great if the enhanced DynamoDb library could work the same way.
Is your Feature Request related to a problem?
I’m always frustrated when I cannot use the new SDK because it is incompatible with other software that my development team depends on.
Proposed Solution
Ideally the annotations can be applied to member variables in the same manner that the SDKv1 dynamoDbMapper annotations could. As a second-best alternative, it could allow the annotations to be applied to member variables, but ignore them; with a little work, Lombok can be set to copy annotations from member variables to the setters and getters.
Describe alternatives you’ve considered
The alternative is to write explicit setters and getters for all dynamo-annotation values. This would be a significant pain point, however; we will probably prefer to stay with SDKv1.
Additional Context
Lombok annotations are as follows:
@Setter
@Getter
public class Customer {
private String id;
private String email;
private Instant registrationDate;
}
Functions “setId(String)”, “getId()”, etc. are all generated automatically, so there is no way to get the annotations onto them.
- I may be able to implement this feature request
Your Environment
- AWS Java SDK version used: 2.13.47
- JDK version used: Java 11
- Operating System and version: Ubuntu (on EC2), AWS Lambda (whatever version of Linux that is)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:35
- Comments:23 (5 by maintainers)
The @Builder(toBuilder = true) Lombok builder feature is also incompatible with enhanced dynamodb annotations. This feature generates a method for creating a builder pre-populated with all the fields of the current object. This feature is extremely useful in the context of DynamoDb mapped immutable objects. For example, code for updating an attribute is very easy to read and more resilient to schema changes:
However, the enhanced DynamoDb validation fails because it detects a ‘toBuilder’ getter method without an associated setter:
Unfortunately, it is not possible to add an annotation to the ‘toBuilder()’ method generated by Lombok. The only work-around is to hand-code the copy builder method.
If compatibility with Lombok (a other field-based object frameworks) is being pursued, this issue should be considered as well.
I also stumbled onto the issue with
toBuilder
support. Would be great if you could address it, as it does make a lot of sense when working with immutable classes. 🙏