I have one spring controller which is sending JSON response to the ajax call present in my script. I have used @ResponseBody in the controller method which directly sends JSON as response when it is invoked via ajax call.
After when I added the JsonSanitizer.sanitize(myJsonString), it is returning as html in the ajax response instead of JSON. Because of that, I am unable to parse the json object now.
Example Code:
@ResponseBody
@RequestMapping(value="/getJson" method="GET")
public String fetchJsonDetails(MyObj obj) {
//DB call based on my object..
//Previously added
//return new Gson().toJson(obj);
//New line added now
return JsonSanitizer.sanitize(new Gson().toJson(obj));
}
After the above added new line, response is coming as html instead of JSON.
Please suggest me to achieve this and let me know if anything required further.
Thanks in advance.