I have a class which contains some String and int fields. I would like to convert this class to the Map<String, AttributeValue>
representation. I know that DynamoDbMapper is doing this internally, but we are not using DynamoDbMapper and I would like to know if there is any existing library that I can use to perform this conversion?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
DynamoDB has a mid-level api that you might find helpful. One of its methods is ItemUtils.toAttributeValues(Item)
. This method allows you to convert from an Item to an attribute value map.
Now, to get an Item, you can construct one manually (but you don’t want to) or you can construct on from a json blob using Item.fromJson(String)
.
Now all that remains is for you to use your favorite serializer to convert from your java data model to json. The methods I’ve mentioned seamlessly handle the rest of the conversion.
TLDR;
Pojo --> json --> Item --> Map<String, AttributeValue>
标签:
amazon-dynamodb