JSON response with incorrect Content-Type
I am trying to create a JSON web service. The response has the correct JSON in the body, unfortunately, the Content-Type in the header is "application/text" instead of "application/json". I need the correct typ in order to play nice with the clients that use my service.
On digging deeper, the aspectJ code puts the content tyoe
Code:
@RequestMapping(value = "/{id}", headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<java.lang.String> ProductController.showJson(@PathVariable("id") BigInteger id) {
Product product = productRepository.findOne(id);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/text; charset=utf-8");
if (product == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>(product.toJson(), headers, HttpStatus.OK);
}
The only option I can see so far is copy this code to the Controller Java class. This is too cumbersome as I have multiple controllers and multiple entities.
Is there something that I can do to change the header to the correct type easily. Or is this a bug or working as designed.
Please help.