4

I am trying to use DynamoDB annotations in nested objects as below:

@DynamoDBTable(tableName=xyz)
class entity1{
    @DynamoDBAttribute
    @DynamoDBTypeConvertedJson
    private List<UserAction> userActions;
}

class UserAction{
    @DynamoDBAutoGeneratedKey
    private String actionId;

    @DynamoDBAttribute
    @DynamoDBAutoGeneratedTimestamp(strategy = DynamoDBAutoGenerateStrategy.CREATE)
    private Long createdTime;
}

I dont see the above attributes are auto generated in UserAction class. I would like to know if these annotation usages are supported in nested objects or not. Please suggest.

Deepak
  • 962
  • 4
  • 17
  • 38

2 Answers2

2

Add @DynamoDbDocument annotation on UserAction class. This annotation will ensure the instance of UserAction class is correctly serialized to a Dynamo DB sub-document before persisting in table.


@DynamoDbDocument
class UserAction{
    //...............
    //...............
}

mango
  • 548
  • 3
  • 8
1

If anyone is looking for a v2 equivalent of @DynamoDBDocument, the following is the annotated way of doing it. For more information check this out.

@DynamoDbBean
class entity1 {
    
    private List<UserAction> userActions;
}

@DynamoDbBean
class UserAction {

    private String actionId;

    private Long createdTime;
}
Hasitha Jayawardana
  • 2,326
  • 4
  • 18
  • 36