Deepak
Deepak

Reputation: 1042

Use of DynamoDB annotations in nested objects

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.

Upvotes: 6

Views: 2687

Answers (2)

Hasitha Jayawardana
Hasitha Jayawardana

Reputation: 2436

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;
}

Upvotes: 3

mango
mango

Reputation: 568

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{
    //...............
    //...............
}

Upvotes: 2

Related Questions