编组未确定的数据类型

Marshalling Undetermined data type

使用自定义 Marshaller 我尝试将 DynamoDB 查询映射到对象

class ownObject {
  private int myInteger;

  @DynamoDBMarshalling(marshallerClass = MasrshallAsInteger.class)
  @DynamoDBAttribute      
  public int getMyInteger {
    return myInteger;
  }

  public void setMyInteger(int newint) {
    myInteger = newint;
  }
}

由于db中的值myIntegerStringNumber两种类型,SDK抛出异常:"Expected S in value {N:123,}" 如果我在另一个对象上使用编组器和 "Expected N in value {S:123,}" 如果我不使用 .

有什么方法可以强制 DynamoDB 使用自定义编组器并将键的值解析为字符串?或者有没有其他方法可以解析未确定类型的数据,但使用 PaginatedQueryList?

我建议您使用 Document SDK 进行分页,将您的项目解析为 Item 对象,进行分页,然后将这些项目转换为您的域。

Table table = new AmazonDynamoDBClient(new DefaultCredentialsProviderChain()).getTable("ownObject");
for (Item item : table.scan()) {
    //convert item to your domain object here
}