aws-sdk-java-v2
aws-sdk-java-v2 copied to clipboard
DynamoDB Enhanced client should ignore @Transient properties
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 thank you for the report, and apologies for the delayed response. Marking this as a bug.
Is there any workaround for this yet?
For anyone else looking. I found 2 solutions:
- Downgraded groovy version to 2 (2.5.15 is what I used)
- Adding the property and annotating it with DynamoDBIgnore
@DynamoDBIgnore MetaClass metaClass;
For anyone else looking. I found 2 solutions:
- Downgraded groovy version to 2 (2.5.15 is what I used)
- 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
}
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;
}
}
⚠️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.