I am trying to create a JSON string using the corresponding key / value pair. In the code below, I am trying to iterate over an AttributeValue list, and then I am trying to customize a JSON string using al.getValue map .
private <T> String createJsonWithEscCharacters(List<AttributeValue<T>> list) { StringBuilder keyValue = new StringBuilder(); if (list != null) { for (AttributeValue<?> al: list) { keyValue.append("\"").append("v").append("\"").append(":").append(" {"); for (Map.Entry<String, String> entry : ((Map<String, String>) al.getValue()).entrySet()) { keyValue.append("\"").append(entry.getKey()).append("\""); keyValue.append(":").append(" \"").append(entry.getValue()).append("\"").append(","); System.out.println(keyValue); } } } return null; }
When I check al , I see value as LinkedHashMap<K,V> , and when I type al.getValue() , it gives me this -
{predictedCatRev=0;101;1,1;201;2, predictedOvrallRev=77;2,0;1,16;3, sitePrftblty=77;2,0;1671679, topByrGms=12345.67, usrCurncy=1, vbsTopByrGmb=167167.67}
So this means that I can repeat the al.getValue() map and use those key/value pair to create a JSON string.
Now I'm trying to make a JSON string, map iteration al.getValue() . So the JSON string should look something like this after repeating the map al.getValue() -
{ "lv": [ { "v": { "predictedCatRev": "0;101;1,1;201;2", "predictedOvrallRev": "77;2,0;1,16;3", "sitePrftblty": "77;2,0;1671679", "topByrGms": "12345.67", "usrCurncy": "1", "vbsTopByrGmb": "167167.67" } } ], }
I am wondering what is the cleanest way to do this? In my code above, I cannot fully execute the JSON String described above, but no matter what code I have above, it can make a small part of the JSON String the way I needed, but not the full JSON String in the path, I'm in search. Can someone help me with this, how will this be the cleanest way to do this?
thanks