使用自定义 Marshaller
我尝试将 DynamoDB 查询映射到对象
class ownObject {
private int myInteger;
@DynamoDBMarshalling(marshallerClass = MasrshallAsInteger.class)
@DynamoDBAttribute
public int getMyInteger {
return myInteger;
}
public void setMyInteger(int newint) {
myInteger = newint;
}
}
由于数据库中的值myInteger
有String
和Number
两种类型,SDK抛出异常:"Expected S在值(value) {N:123,}" 如果我使用编码器和 "Expected N in value {S:123,}" 如果我不使用另一个对象。 p>
有什么方法可以强制 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
}
关于android - 编码未确定的数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42998730/