com.amazonaws.util.json.JSONObject Below is the List, i want to convert it into json string.
List<JSONObject> jsonObjlist is
[{"Attribute":"EmailAddress","Value":"[email protected]"}, {"Attribute":"Source","Value":"Missing_Fixed"}, {"Attribute":"mx_Lead_Status","Value":"Registered User"}, {"Attribute":"mx_Age","Value":""}, {"Attribute":"mx_LoginID","Value":"[email protected]"}, {"Attribute":"mx_Registration_Source","Value":"EMAIL"}]
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
String arrayToJson = objectMapper.writeValueAsString(jsonObjlist);
Output i get is
[{"map":{"Attribute":"EmailAddress","Value":"[email protected]"}},{"map":{"Attribute":"Source","Value":"Missing_Fixed"}},{"map":{"Attribute":"mx_Lead_Status","Value":"Registered User"}},{"map":{"Attribute":"mx_Age","Value":""}},{"map":{"Attribute":"mx_LoginID","Value":"[email protected]"}},{"map":{"Attribute":"mx_Registration_Source","Value":"EMAIL"}}]
Desired out put is
"[{"Attribute":"EmailAddress","Value":"[email protected]"}, {"Attribute":"Source","Value":"Missing_Fixed"}, {"Attribute":"mx_Lead_Status","Value":"Registered User"}, {"Attribute":"mx_Age","Value":""}, {"Attribute":"mx_LoginID","Value":"[email protected]"}, {"Attribute":"mx_Registration_Source","Value":"EMAIL"}]"
importstatements, as most readers (including me) will otherwise assume that you are usingorg.jsonclasses.