Announcement Announcement Module
Collapse
No announcement yet.
@ResponseBody jackson handler adding leading [ character Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ResponseBody jackson handler adding leading [ character

    I have the following REST controller method:

    Code:
    @RequestMapping(value="/{id}", method=RequestMethod.GET, produces="application/json")
    public @ResponseBody Property readProperty(@PathVariable long id, HttpServletResponse response)
    {
        Property p =  getPropertyService().getProperty(id);
        if(p == null) 
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return p;
    }
    For some reason the response from this method is like this:

    Code:
    [{"id":1982,"name":"Test Property 1","description":"Test Description",...
    It looks lika an array (it begins with [ ) whereas a Property should just be a scalar object value.

    The other weird thing is that there is no closing ] at the other end:

    Code:
    "location":null}
    The same thing does not happen when calling the ObjectMapper directly:

    Code:
    System.out.println(new ObjectMapper().writeValueAsString(property));
    Produces the expected result i.e:

    Code:
    {"id":1982,"name":"Test Property 1","description":"Test Description",...
    The method used to work fine but i just switched my project to maven for building and dependencies, thats when the tests started failing!!

    Cheers! NFV
Working...
X