I can have Spring convert my json POST submission into an object with a method like this:
@RequestMapping(value = "/doSomething", method = RequestMethod.POST)
public ResponseEntity<String> doSomething(@RequestBody SomeUsefulPojo usefulPojo) {
// use the useful pojo, very nice
}
I can get JSR-303 validation by setting up all the application context magic, and by creating my post method as such and submitting with form-encoded values:
@RequestMapping(value = "/doSomething", method = RequestMethod.POST)
public ResponseEntity<String> doSomething(@Valid SomeUsefulPojo validPojo) {
// use validPojo, I'm happy
}
Problem is, the second one appears to want to use a form-encoded approach, whereas I want the JSON handed in. Any way to get the best of both worlds - validation AND json POST? I've tried @Valid and @RequestBody together, but it doesn't invoke the validation that way.
Ideas?