I want to save an object that is encoded as a Json string to DynamoDB using the AWS Java SDK 2.0.
In the AWS Java SDK 1.n, it is possible to convert standard Json strings to DynamoDB AttributeValues
using Item.fromJSON(myJsonString).toAttributeValues()
.
Though it is possible to use both SDKs at once, the AttributeValue
defined by the two SDK versions (1.11, 2.0) are not the same and cannot be used interchangeably.
Is there any AWS-provided or community-standard way to go from a json string/blob to a Map<String, AttributeValue>
for the AWS Java SDK 2.0?
Please note—this question is asking about how to solve the problem for AWS Java SDK 2.0, not the dynamodbv2 model of AWS Java SDK 1.n. If you think this question is a duplicate, please double check the SDK version of the question/answer that it duplicates.
An example for converting JSON to AttributeValue of DynamoDB
String productString = readFileFromResources("data/categoryFix.json");
HashMap<String,Object> result = new ObjectMapper().readValue(productString, HashMap.class);
Map<String, AttributeValue> attributes = InternalUtils.fromSimpleMap(result);
Above code worked well, even though InternalUtils is deprecated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With