I have a method that returns a fully formatted JSON as a String, ex { type: "", List1: []…}
I’m trying to return that in a way that the browser interprets it as a JSON (Firefox). I’ve tried specifying that it produces="text/plain" but no luck.
I can’t put it in a wrapper class as it’s already formatted.
I tried specifying produces="text/plain" and @ResponseBody. No luck, still interpreted as text, not JSON.
@GetMapping(value="/v1/Count", produces="text/plain"
@ResponseBody
public String getCount(@RequestParam...) {
return "{type: "", List1: []...}";
}
3
Answers
Please show us the controller method you told us about
Try using produces=MediaType.APPLICATION_JSON_VALUE. For example annotate your controller method with:
Try to specify the
produces
in the annotation@RequestMapping
asapplication/json
and it will help you. For example: