I have this piece of code:
@RequestMapping(value = "/test", produces = "text/plain")
@ResponseBody
public Object test() {
return "true";
}
And what I want is returning in this case "true" with 'text/plain' type even when my accept header says 'application/json' or anything else. Now I get 406 when I do that. Is there simple way to do such a thing? I mean really simple? I'd rather not change my config files that will affect more than just this one method.
EDIT: I found partial solution
@RequestMapping(value = "/test")
@ResponseBody
public Object test(){
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.TEXT_PLAIN);
return new ResponseEntity<>("true", responseHeaders, HttpStatus.OK);
}
But is there anyone who knows simpler, shorter solution?