How to remove escape characters when JSON is added to model in spring rest controller
Instead of adding the string to model return JSON directly
@RequestMapping(value="/all")public @ResponseBody String getJson(){ //Logic return json; }
You can use replaceAll:
String json = serviceDao.getResponseJson();if (json != null && !json.isEmpty()) { model.addAttribute("result", json.replaceAll("\\\\", ""));}
If you are using spring, you can use @ResponseBody
and directly return your class object instead of String.
You can refer example given in this link.
Also don't forget to include maven dependency.
<dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.12</version></dependency>