我有一个用于在Dynamo表上执行CRUD操作的类。其属性之一是Map<String,Object>
,因为它需要同时支持Map<String,String>
和Map<String,Map<String,String>>
和Map<String,Map<String,Map<String,String>>>
@DynamoDBDocument
@Getters
@Setters
@JsonIgnoreProperties(ignoreUnknown = true)
public class Foo {
@DynamoDBAttribute
@DynamoDBHashKey
private String id;
@DynamoDBAttribute
@DynamoDBRangeKey
private String type;
@DynamoDBAttribute
private String subType;
@DynamoDBAttribute
private Map<String, Object> payload;
public void setPayload(Map<String, String> payload){
Map<String, Object> map = new HashMap<>();
payload.forEach(map::put);
this.payload = map;
}
}
这与写入数据库的效果很好,它成功地接受了两种类型,没有问题。我遇到的问题是当我尝试查询表以获取与特定type
匹配的列表时。我收到错误消息Foo<payload> could not unconvert attribute
。这是我的查询方式:
public List<Foo> getFooList (String type){
DynamoDBQueryExpression query = new DynamoDBQueryExpression();
query.withRangeKeyCondition("type",
new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withS(type)));
}
List<Foo> Foos = getMapper().query(Foo.class, query);
}
我在做什么错,还有更好的方法吗?