How to convert between Json and Map in


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

Above code worked well, even though InternalUtils is deprecated.

Leave a Reply