【发布时间】:2019-09-05 19:21:02
【问题描述】:
我正在为 dynamodb 使用事务。并且事务 Put 请求将 com.amazonaws.services.dynamodbv2.document.Item 作为输入参数。所以,我需要将 POJO 转换为 Map。
到目前为止,我已经尝试使用 Jackson 将对象转换为字符串,然后将字符串转换为项目。 以下是我尝试过的代码。
ObjectMapper objectMapper = new ObjectMapper();
String jsonStr = null;
try {
jsonStr = objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
Item item = new Item().withJSON("document", jsonStr);
Map<String,AttributeValue> attributes = ItemUtils.toAttributeValues(item);
return attributes.get("document").getM();
问题是,“Set”类型的字段转换后返回“List”。 有什么建议可以解决这个问题吗?
【问题讨论】:
-
@MatthewPope,我已经按照您的回答实施了解决方案。但问题依然存在。
标签: java amazon-dynamodb