Home » Java » java – How to store collection of values as attributes in DynamoDB table?-Exceptionshub

java – How to store collection of values as attributes in DynamoDB table?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a structure with collection of items inside that need to stored in DynamoDB table. Using current implementation items are stored as JSON but I would like to have them as unique attributes in table. Is it possible using spring-data-dynamodb library?

@Getter
@Setter
@DynamoDBTable(tableName = "orders")
public class Order {
    @DynamoDBHashKey
    @DynamoDBAutoGeneratedKey
    private String id;
    @DynamoDBAttribute
    private long userId;
    @DynamoDBAttribute
    private List<Item> items;
}

@Getter
@Setter
@DynamoDBDocument
public class Item {
    @DynamoDBAttribute
    private String name;
    @DynamoDBAttribute
    private String value;
}

Expected result:

Table: orders
| id | userId | item_name1  | item_name2  | item_name3  |
| s2 | 234    | item_value1 | item_value1 | item_value3 |
How to&Answers: