aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

DynamoDB Enhanced client should ignore @Transient properties

Open chrylis opened this issue 3 years ago • 5 comments

The DynamoDB Enhanced client, when building a TableSchema.fromClass, lists the properties and then tries to map them onto DynamoDB attributes. However, the code as it currently stands is incompatible with Groovy, because it looks for a mapping from the groovy.lang.MetaClass metaClass property, predictably does not find it, and throws an exception.

This property (more specifically the getMetaClass() accessor) is annotated with @java.beans.Transient, which is a standard JDK annotation and automatically sets the attribute transient=true on the PropertyDescriptor.

The client should, in createStaticTableSchema, filter out properties that are annotated @Transient. In addition to preserving compatibility, this is the general semantic expectation for the annotation.

SDK version: 2.16.20

chrylis avatar Mar 24 '21 23:03 chrylis

@chrylis thank you for the report, and apologies for the delayed response. Marking this as a bug.

debora-ito avatar Apr 07 '21 22:04 debora-ito

Is there any workaround for this yet?

theskylinetech avatar Oct 06 '21 13:10 theskylinetech

For anyone else looking. I found 2 solutions:

  1. Downgraded groovy version to 2 (2.5.15 is what I used)
  2. Adding the property and annotating it with DynamoDBIgnore @DynamoDBIgnore MetaClass metaClass;

theskylinetech avatar Oct 07 '21 11:10 theskylinetech

For anyone else looking. I found 2 solutions:

  1. Downgraded groovy version to 2 (2.5.15 is what I used)
  2. Adding the property and annotating it with DynamoDBIgnore @DynamoDBIgnore MetaClass metaClass;

How do you annotate a property if the annotation is for method only? (at least in the latest version: 2.17.182)

It even works to override and annotate the method, but it has many limitations:

case 1: return Stackoverflow exception (infinite recursion)

    @DynamoDbIgnore
    @Override
    MetaClass getMetaClass() {
       super.getMetaClass()
    }

case 2: Throw NullPointerException when call any getter

    @DynamoDbIgnore
    @Override
    MetaClass getMetaClass() {
        null
    }

marcusvoltolim avatar May 04 '22 02:05 marcusvoltolim

What I've been doing in Groovy projects is creating the classes mapped as .java and using lombok @Getter/@Setter annotations and just adding getter methods for @DynamoDbPartitionKey and @DynamoDbSortKey. Example:

import java.util.List;

@Getter
@Setter
@DynamoDbBean
public class User {

    private String id;
    private String authority;
    private String name;
    private String email;
    private List<Address> addresses;

    @DynamoDbPartitionKey
    public String getId() {
        return id;
    }

    @DynamoDbSortKey
    @DynamoDbAttribute("authorityLevel")
    public String getAuthority() {
        return authority;
    }
    
}

marcusvoltolim avatar May 04 '22 02:05 marcusvoltolim

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Oct 07 '22 20:10 github-actions[bot]