New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring MVC Binding Lifecycle differs between @RequestBody arguments and plain JavaBean arguments [SPR-6740] #11406
Comments
Keith Donald commented Other questions to answer:
|
Simon Wong commented I have read the source code of the mvc-ajax spring samples. How it deals with validation exception is putting the ValidationResult in Map and returned it (with the HTTP status code is a CLIENT_ERROR code). I think setting the return type as a combination (in Map<String, ?>) of ValidationResult/domain object will cause the I guess the binding exceptions should be handled automatically (maybe configurable), maybe output to |
Keith Donald commented This issue has been brought up multiple times on our blog here: http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/#comment-173191 |
Rossen Stoyanchev commented I'm resolving this issue as complete. Use of We don't support a BindingResult argument after |
We are switching from
I understand the reason behind this as JacksonMapping is a complete different process then Spring Binding. But it is annoying to have At least this behavior is documented here: And discussed here: |
This is an 8 year old issue and the information in it is equally old. Please make sure you've read the latest documentation. Keep in mind the issue tracker here is for issues and not for questions. |
Sorry for this. I still think this is an issue as you have access to the BindingResult with |
How so? If you actually click the link I provided, which I will assume you did not, it's not the same as the one you provided, and the very second example has BindingResult. |
I have read it all, of course. Of course, you can add a BindingResult object to the method parameter, but it does not include Binding problems within Jackson. This differs from @ModelAttribute. But to make my words understandable I wrote a small test project. https://github.com/kicktipp/requestbody-demo
|
In the case In the case of |
In case of |
Keith Donald opened SPR-6740 and commented
Differences I've noticed so far:
When using
@RequestBody
to bind the request body to a JavaBean, you cannot also declare a BindingResult parameter to trap bind failures. Any failures result seems to result in an exception (500) being thrown. For example, when Jackson fails to bind a 500 error is returned and you have no control over this like you do when failures are first added to the BindingResult context.When using
@RequestBody
you cannot trigger execution of a validation step post binding with the@Valid
annotation.We should look at getting consistency between the "traditional" DataBinder mechanism and the
@RequestBody
mechanism where it is possible. If it's not possible or practical, we should at least document the differences between traditional binding and@RequestBody
/@ResponseBody
usage.Affects: 3.0 GA
Issue Links:
4 votes, 7 watchers
The text was updated successfully, but these errors were encountered: