question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhanced DynamoDB annotations are incompatible with Lombok

See original GitHub issue

Describe 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:open
  • Created 3 years ago
  • Reactions:35
  • Comments:23 (5 by maintainers)

github_iconTop GitHub Comments

13reactions
nadernader99commented, Oct 4, 2020

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:

    Customer customer = table.getItem(customerKey);
    Customer updated = customer.toBulder().name(updatedName).build();
    table.putItem(updated);

However, the enhanced DynamoDb validation fails because it detects a ‘toBuilder’ getter method without an associated setter:

A method was found on the immutable class that does not appear to have a matching setter on the builder class. Use the @DynamoDbIgnore annotation on the method if you do not want it to be included in the TableSchema introspection.

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.

5reactions
bigunyakcommented, Feb 3, 2021

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. 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lombok Annotations with DynamoDB annotations
The DynamoDBMapper is trying to map that request based on your annotations. Your class has the @DynamoDBRangeKey annotation, and the GetItem ...
Read more >
DynamoDB Enhanced Client for Java: Missing Setters Cause ...
Solution. Make sure every DynamoDB attribute on your entity has a publicly-accessible setter with the same name (case-sensitive) as the getter.
Read more >
aws/aws-sdk-java-v2 - Gitter
I was moving some of our code over to SDKv2 as a test, but hit a problem with the enhanced DynamoDb annotations: They...
Read more >
Java Annotations for DynamoDB - AWS Documentation
This section describes the annotations that are available for mapping your classes and properties to tables and attributes in Amazon DynamoDB.
Read more >
Micronaut Data - GitHub Pages
If you intend to use Lombok with Micronaut Data then you must place the Lombok annotation processor before the Micronaut processors in your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found