In my webapp, all my message converters are in place, and if I change getContent below to return a bean/pojo, it returns as " application/json;charset=UTF-8", which is expected, but I now want to serve JSON "as is".
E.g. I have a simple stub web service with which users can PUT a blob of JSON content which is persisted somewhere, and then an equivalent GET call to read it back.
@Controller
public class StubController {
@Autowired
@Qualifier("keyValueStore")
private KVStore kv;
@RequestMapping(value = "/stub/{id}", method = RequestMethod.GET)
public @ResponseBody
String getContent(@PathVariable("id") final String id) {
return kv.get(id);
}
@RequestMapping(value = "/stub/{id}", method = RequestMethod.PUT)
public String putContent(@PathVariable("id") final String id, @RequestBody String body) {
kv.set(id, body);
return "redirect:/stub/"+id;
}
}
However, the getter returns header "Content-Type: text/html;charset=UTF-8" if I call http://host/stub/123.json in the browser. My guess that this is happening is because I'm not returning anything that is "converted" by the Jackson converter, hence the return header isn't modified.
I need it to be application/json -- any ideas what to do? Perhaps an annotation with which I can specify the return headers?