没有注释的DynamoDB文档字段的DynamoDBTypeConverter [英] DynamoDBTypeConverter for DynamoDB document field without annotations

查看:133
本文介绍了没有注释的DynamoDB文档字段的DynamoDBTypeConverter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在DynamoDB中有一些条目,这些条目具有DynamoDB文档格式的以下字段:

I have some entries in DynamoDB, which have an field as follows, in DynamoDB document format:

{" foo":{"N":"45";},"bar":{"N":"12";}}

我有一个表示文档类型的Java类:

I've got a Java class representing the document type:

public class FooBar {
  private final int foo;
  private final int bar;

  public FooBar(
      int foo,
      int bar
  ) {
    this.foo = foo;
    this.bar = bar;
  }

  public int getFoo() {
    return foo;
  }

  public int getBar() {
    return bar;
  }
}

我想使用 DynamoDB映射器获取并将行放入表中(为简洁起见,省略了代表整个行的中间类).我不想将DynamoDB注释( @DynamoDBDocument @DynamoDBAttribute 等)添加到 FooBar 类,因为它们需要零参数构造方法和设置方法,但这应该是不可变的数据对象.

I'd like to use a DynamoDB mapper to get and put rows to the table (the intermediate class representing the entire row is omitted for brevity). I don't want to add the DynamoDB annotations (@DynamoDBDocument, @DynamoDBAttribute etc) to the FooBar class as they require a zero-argument constructor and setter methods but this should be an immutable data object.

因此,我想使用 DynamoDBTypeConverter (如这里)来编写自己的转换,但找不到合适的源"类型(以替换 [?] ):

Therefore, I'd like to use a DynamoDBTypeConverter (as described here) to write my own conversion, but I cannot find a suitable 'source' type (to replace [?]):

class FooBarConverter implements DynamoDBTypeConverter<[?], FooBar> {
  @Override
  public [?] convert(FooBar object) {
    ...
  }

  @Override
  public FooBar unconvert([?] object) {
    ...
  }
}

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆