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?
-
Readout doc docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/…IMParasharG– IMParasharG2019-01-29 09:43:08 +00:00Commented Jan 29, 2019 at 9:43
-
Hey, did the answer end up working for you? If it did, you should accept it so that other SO users know that it solves the problem. If you had to tweak a few things or if you used a different solution, leave a comment or add your own answer to share that knowledge with others.Matthew Pope– Matthew Pope2019-07-20 05:40:59 +00:00Commented Jul 20, 2019 at 5:40
Add a comment
|
1 Answer
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>