Spring 3.0 making JSON response using jackson message converter

You need the following:

  1. Set annotation-driven programming model: put <mvc:annotation-driven /> in spring.xml
  2. Place jaskson jar (Maven artifactId is org.codehaus.jackson:jackson-mapper-asl) in classpath.
  3. Use as the following:

    @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
    public @ResponseBody Foo method(@Valid Request request, BindingResult result){
    return new Foo(3,4)
    }
    

This works for me.

Please note, that

  1. @ResponseBody is applied to return type, not to the method definition.
  2. You need @RequestMapping annotation, so that Spring will detect it.

Leave a Comment