DynamoDB注解在嵌套对象中的使用

huangapple go评论70阅读模式
英文:

Use of DynamoDB annotations in nested objects

问题

我正试图在嵌套对象中使用DynamoDB注解,如下所示:

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

我没有看到上述属性在UserAction类中被自动生成。我想知道这些注解用法是否支持嵌套对象。请提供建议。

英文:

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

@DynamoDBTable(tableName=xyz)
class entity1{
    @DynamoDBAttribute
    @DynamoDBTypeConvertedJson
    private List&lt;UserAction&gt; 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.

答案1

得分: 2

UserAction 类上添加 @DynamoDbDocument 注释。此注释将确保在将 UserAction 类的实例持久化到表中之前,它会被正确地序列化为 Dynamo DB 子文档。

@DynamoDbDocument
class UserAction {
    //...............
    //...............
}
英文:

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

答案2

得分: 1

以下是标有注释的方法,用于查找 @DynamoDBDocument 的 v2 版本等效方式。有关更多信息,请查看此链接

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

@DynamoDbBean
class UserAction {

    private String actionId;

    private Long createdTime;
}
英文:

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&lt;UserAction&gt; userActions;
}

@DynamoDbBean
class UserAction {

    private String actionId;

    private Long createdTime;
}

huangapple
  • 本文由 发表于 2020年8月15日 10:32:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/63422042.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定