I am trying to return the json object into the hashmap of response entity object along with other fields, but I getting something else for the fields where the corresponding value is a json object.
I tried debugging but every hashmap in the response flow was having the required response structure.
I tried sending this from the backend:
HashMap<String, Object> hashMap = new HashMap<>();
HashMap<String, Object> hashMap2 = new HashMap<>();
JSONObject jsonObject = new JSONObject();
jsonObject.put("key", "dummy value");
hashMap2.put("key", "dummy value");
hashMap2.put("new key", jsonObject);
hashMap.put("data", jsonObject);
hashMap.put("data2", hashMap2);
hashMap.put("extra field", "extra value");
return new ResponseEntity<>(hashMap, HttpStatusCode.valueOf(200));
And I am getting this in the response:
{
"data": {
"empty": false,
"mapType": "java.util.HashMap"
},
"data2": {
"new key": {
"empty": false,
"mapType": "java.util.HashMap"
},
"key": "dummy value"
},
"extra field": "extra value"
}