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

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

Use of DynamoDB annotations in nested objects

问题

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

  1. @DynamoDBTable(tableName=xyz)
  2. class entity1{
  3. @DynamoDBAttribute
  4. @DynamoDBTypeConvertedJson
  5. private List<UserAction> userActions;
  6. }
  7. class UserAction{
  8. @DynamoDBAutoGeneratedKey
  9. private String actionId;
  10. @DynamoDBAttribute
  11. @DynamoDBAutoGeneratedTimestamp(strategy = DynamoDBAutoGenerateStrategy.CREATE)
  12. private Long createdTime;
  13. }

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

英文:

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

  1. @DynamoDBTable(tableName=xyz)
  2. class entity1{
  3. @DynamoDBAttribute
  4. @DynamoDBTypeConvertedJson
  5. private List&lt;UserAction&gt; userActions;
  6. }
  7. class UserAction{
  8. @DynamoDBAutoGeneratedKey
  9. private String actionId;
  10. @DynamoDBAttribute
  11. @DynamoDBAutoGeneratedTimestamp(strategy = DynamoDBAutoGenerateStrategy.CREATE)
  12. private Long createdTime;
  13. }

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 子文档。

  1. @DynamoDbDocument
  2. class UserAction {
  3. //...............
  4. //...............
  5. }
英文:

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.


  1. @DynamoDbDocument
  2. class UserAction{
  3. //...............
  4. //...............
  5. }

答案2

得分: 1

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

  1. @DynamoDbBean
  2. class entity1 {
  3. private List<UserAction> userActions;
  4. }
  5. @DynamoDbBean
  6. class UserAction {
  7. private String actionId;
  8. private Long createdTime;
  9. }
英文:

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.

  1. @DynamoDbBean
  2. class entity1 {
  3. private List&lt;UserAction&gt; userActions;
  4. }
  5. @DynamoDbBean
  6. class UserAction {
  7. private String actionId;
  8. private Long createdTime;
  9. }

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:

确定