Let's say I have this situation in which I got a DynamodbStreamRecord
inside an AWS Lambda.
From this stream record (variable named record
), I have a chain of Java methods that extracts a map in this way:
Map<String, AttributeValue> w1Data = record.getDynamodb().
getNewImage(). // obtain the image
get("DT"). // get from key "DT"
getM(). // obtain the related map
get("w1_data"). // get from key "w1_data"
getM(); // obtain the related map
Now, I need to transform such w1Data
map in a JSON string and I tried to use the org.json.JSONObject
constructor that takes a map as input parameter, followed by a toString()
:
String jsonRepr = new JSONObject(w1Data).toString();
But I obtained this strange string:
'{"SessionExtraInfo":"{M: {Info={M: {CampaignID={N: 3,}, OriginID={N: 1,}, EntitySourceClassID={N: 8,}},}},}"}'
which instead should be something like this:
'{"SessionExtraInfo": {"Info": {"OriginID": "1", "CampaignID": "3", "EntitySourceClassID": "8"}}}'
Do you have any suggestion to create a valid JSON string from this map without showing the data types specified by DynamoDB?
Thank you very much