Announcement Announcement Module
Collapse
No announcement yet.
JSON response with incorrect Content-Type Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    Please log a ticket for this for us to investigate further.

    Comment


    • #3
      The content type has been "application/text" for as long as I can tell from the revision history (noting that the relevant code was previously in o.s.r.addon.web.mvc.controller.scaffold.json.WebJs onMetadata). I've checked with the original developer whether there was some special reason for not using "application/json" as the content type, and there doesn't seem to have been one.

      I've fixed this as ROO-2965.
      Last edited by Andrew Swan; Dec 12th, 2011, 09:26 PM.

      Comment


      • #4
        Cool things,thx for your sharing

        Comment

        Working...
        X