I need to convert a AWS DYNAMODB JSON to a standard JSON object. so I can remove the data type from the DynamoDB JSON Something more like:
in DYNAMODB JSON:
Amazon has an internal utility that can do the core of the job in 1 line.
Map jsonMapWithId = InternalUtils.toSimpleMapValue(attributeValueMap);
A long version which contains some configurations:
import com.amazonaws.services.dynamodbv2.document.internal.InternalUtils;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import java.lang.Map;
import java.lang.HashMap;
public class JsonConvert {
public static void main(String[] args) {
Map jsonMap = new HashMap();
jsonMap.put("string", "foo");
jsonMap.put("number", 123);
Map innerMap = new HashMap();
innerMap.put("key", "value");
jsonMap.put("map", innerMap);
AttributeValue attributeValue = InternalUtils.toAttributeValue(jsonMap);
Map attributeValueMap = new HashMap();
attributeValueMap.put("id", attributeValue);
Map jsonMapWithId = InternalUtils.toSimpleMapValue(attributeValueMap);
Map jsonMap = jsonMapWithId.get("id"); // This is a regular map, values are not Amazon AttributeValue
Gson gson = new Gson();
String json = gson.toJson(jsonMap);
System.out.println(json);
}
}