Getting JSR-303 validation with JSON posted object?

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 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 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?
The bug is apparently fixed in v3.1 M2 [Linked Solution][1] [1]: stackoverflow.com/a/7811192/41223

以上就是Getting JSR-303 validation with JSON posted object?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JSON 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏