You need the following:
- Set annotation-driven programming model: put
<mvc:annotation-driven />
inspring.xml
- Place jaskson jar (Maven artifactId is
org.codehaus.jackson:jackson-mapper-asl
) in classpath. -
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
@ResponseBody
is applied to return type, not to the method definition.- You need
@RequestMapping
annotation, so that Spring will detect it.