![](/img/trans.png)
[英]DynamoDB getAccumulatedConsumedCapacity on ItemCollection always returns NULL
[英]DynamoDB ItemCollection<QueryOutcome> to java object
我想将 ItemCollection 转换为我的 java pojo object。我现在想通过以下方式这样做。最好的方法是什么?
QuerySpec spec = new QuerySpec()
.withKeyConditionExpression("txn_id = :txnId")
.withFilterExpression("rrn = :rrn")
.withValueMap(new ValueMap()
.withString(":txnId", txnId)
.withString(":rrn", rrn))
.withConsistentRead(true);
ItemCollection<QueryOutcome> items = table.query(spec);
在这里我得到了 ItemCollection。现在我将把它转换为我的 java pojo:-
Iterator<Item> iter = items.iterator();
while (iter.hasNext()) {
String txn = iter.next().toJSON();
Gson gson = new Gson();
Test t = gson.fromJson(txn, Test.class);
return t;
}
Is there a way to convert dynamodb fetch value( ItemCollection) to java pojo directly like we do in mysql?Why i will always get json then covert to pojo.We don't do so in other DB like mysql or oracle DB.
文本.java
public class Test implements Serializable {
@DynamoDBAttribute(attributeName = "txn_id")
@JsonProperty("txn_id")
@DynamoDBHashKey
private String txnId;
private String umn;
private String note;
@DynamoDBAttribute(attributeName = "rrn")
private String rrn;
@DynamoDBAttribute(attributeName = "expire_on")
private Date expireOn;
@DynamoDBAttribute(attributeName = "expire_after")
private Integer expireAfter;
@DynamoDBAttribute(attributeName = "created_on")
@DynamoDBAutoGeneratedTimestamp(strategy= DynamoDBAutoGenerateStrategy.CREATE)
private Date createdOn;
}
是的,看看DynamoDBMapper 。 使用相同的 pojo 注释...
CatalogItem partitionKey = new CatalogItem();
partitionKey.setId(102);
DynamoDBQueryExpression<CatalogItem> queryExpression = new DynamoDBQueryExpression<CatalogItem>()
.withHashKeyValues(partitionKey);
List<CatalogItem> itemList = mapper.query(CatalogItem.class, queryExpression);
for (int i = 0; i < itemList.size(); i++) {
System.out.println(itemList.get(i).getTitle());
System.out.println(itemList.get(i).getBookAuthors());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.