aws-sdk-java-v2
aws-sdk-java-v2 copied to clipboard
Support for using Lombok @Builder on class annotated with DynamoDbImmutable containing ignored attributes
Describe the feature
Currently, ImmutableIntrospector
checks for a strict 1:1 relationship between the immutable class getter methods and builder class setter methods. This means annotating a getter with @DynamoDbIgnore
but not the associated setter inside the builder will throw an exception.
I propose adding a simple condition where if the getter is annotated with @DynamoDbIgnore
, then the introspection will skip looking for the setter method altogether (or, in other words, handle this case so that the setter method is also implicitly ignored).
Use Case
This will be extremely useful for classes with many fields or when just a few attributes need to be ignored.
For example, I currently have an immutable data class with 20+ fields and I want to exclude just one as an attribute. While I could annotate the class with Lombok's @Builder
, there currently isn't support to exclude a single field from the generated builder. The only workarounds are either defining the Builder class myself and overriding the setter methods I want to exclude or creating a new constructor with the other 19 fields and annotating this constructor with @Builder
instead of the class.
Both options are extremely frustrating. If I had a class with 100 fields, excluding just 1 means writing a special constructor with 99 fields and excluding 50 means writing a builder class with 50 overridden setter methods.
It would be ideal to keep @Builder
on the class and have @DynamoDbIgnore
on the getter method be enough to skip looking for it in the builder so I don't need to add unnecessary code.
This also makes using @DynamoDbIgnore
way more intuitive since I had it assumed it would already do this--trying to figure out why I was getting errors led me here.
Proposed Solution
Right now the issue seems to be caused by the getter method being filtered out from getters
since it's ignored but the setter method remaining in indexedBuilderMethods
, causing the exception to be thrown when indexedBuilderMethods
is found to be not empty.
You could maybe modify isMappableMethod
to remove the method.getAnnotation(DynamoDbIgnore.class) == null
condition and handle this elsewhere. Or add an extra loop prior to checking if indexedBuilderMethods
is empty to go through and remove the leftover setters that have getters annotated with @DynamoDbIgnore
.
Other Information
No response
Acknowledgements
- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
AWS Java SDK version used
2.26.10
JDK version used
21.0.3
Operating System and version
macOS 14.5 (23F79)