DynamoDB Enhanced Client Polymorphic Types
See original GitHub issueWe should support reading/writing base types using the DynamoDB Enhanced Client.
Potential syntax/example (not yet implemented):
@DynamoDbBean
@DynamoDbSubtypes({Employee.class, Customer.class})
public abstract class Person {
@DynamoDBHashKey
private long id;
private String name;
}
@DynamoDbBean
private class Employee extends Person {
}
@DynamoDbBean
private class Customer extends Person {
}
DynamoDbEnhancedClient client = DynamoDbEnhancedClient.create();
DynamoDbTable<Person> people = client.table("people", TableSchema.fromBean(Person.class));
Employee bob = new Employee();
bob.setId(1);
bob.setName("Bob the Builder");
Customer lfh = new Customer();
lfh.setId(2);
lfh.setName("Low Flying Hawk");
people.putItem(bob);
people.putItem(lfh);
assertThat(people.getItem(Key.builder().partitionValue(1).build())).isInstanceOf(Employee.class);
assertThat(people.getItem(Key.builder().partitionValue(2).build())).isInstanceOf(Customer.class);
Issue Analytics
- State:
- Created 3 years ago
- Reactions:39
- Comments:21 (9 by maintainers)
Top Results From Across the Web
Using the DynamoDB Enhanced Client in the AWS SDK for ...
It offers a straightforward way to map client-side classes to DynamoDB tables. You define the relationships between tables and their corresponding model classes...
Read more >Querying an Item Collection of Distinct Types Java
Does anyone have suggestions for dealing with a query on an item collection? Example: an item collection which contains a Customer, an Order, ......
Read more >EnhancedAttributeValue (AWS SDK for Java - 2.18.35)
software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute. ... provided that exposes a polymorphic way of converting a value into another type.
Read more >DynamoDBMapper support for inheritance - Stack Overflow
Let me know if this is supported. Or any workarounds for storing polymorphic types from Java in DynamoDb. Thanks in advance,.
Read more >How to model one-to-many relationships in DynamoDB
Denormalization by using a complex attribute; Denormalization by duplicating data; Composite primary key + the Query API action; Secondary index ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anyone tracking this issue, I have created a PR with an implementation that I hope addresses the needs identified here. It will probably be at least a couple of weeks before this gets final approval and makes it into the release, so it would be extremely valuable if people could try it out and see if there are any rough edges or improvements I could make before it becomes difficult to change it after release. It’s a complex change, so lots of scope for not getting things quite right. Instructions on how to declare subtypes are in the new README.md file in the dynamodb-enhanced module under the section titled ‘Using subtypes…’. https://github.com/aws/aws-sdk-java-v2/pull/2861
This would be super useful!