Results 1 to 4 of 4

Thread: JSON response with incorrect Content-Type

  1. #1
    Join Date
    Feb 2006
    Posts
    2

    Default 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. #2
    Join Date
    Dec 2005
    Posts
    930

    Default

    Please log a ticket for this for us to investigate further.
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

  3. #3
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Default

    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 at 09:26 PM.
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

  4. #4

    Default

    Cool things,thx for your sharing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •