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
Allow Errors/BindingResult after @RequestBody [SPR-7114] #11774
Comments
Matt Goldspink commented I'm also hitting this issue. Is it a bug that I can't do:
It would be nice to extend the validation to logic to other request data types (cookies, headers, request body) and not just model attribute. I can see use cases where I may store a cookie which stores JSON on the client side (to prevent multiple requests) and send it back to the server to be deserialised and validated. Stack trace below:
|
Matt Goldspink commented Ok after digging around a bit more I see a BindingResult object doesn't make sense because technically no data binding was done (at least not by Spring's data binding classes). Having said that if I change to an Errors object I don't see why the code couldn't be changed to allow the JSR 303 validator to be run over the result of the Jackson deserialization and passed into the method. I see in Keith's blog post here (http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/) he is doing the validation manually, but personally this seems like a feature Spring could do for me. I don't even care if I have to change Errors to be Set<ConstraintViolation<Projects>>, just some way for JSON and validation to happen out of the box would be fantastic. |
Matt Goldspink commented Attaching my patched version of the HandlerMethodInvoker which seems to work for me (not the most ideal solution to the problem but for now it seems to work). |
Guillaume Bilodeau commented Sure would eliminate some boilerplate code to have this. Looking forward to it! |
Michel Zanini commented Please resolve this issue. I can't make this work: public Response post( } |
Rossen Stoyanchev commented This ticket was opened a while ago, so let me first mention that in Spring 3.1 we support Neither The rational is that with
|
Marc Logemann commented I also hit this issue today and i must admit that i am also not happy with the way it works. For example we want to return a custom JSON error object back to the client dont want some kind of standard behavior. Furthermore the way spring operates should be content agnostic. This means from programming perspective it should not make a difference if we post url-formencoded to the backend (which is supported by BindingResult) or JSON. Spring should work the same. Any feedback welcomed. |
Marc Logemann commented solved sounds good but what version will have this included? Fix Version is still set to "none" in this ticket. |
Rossen Stoyanchev commented Good catch. It's in master now and will be in the 3.2 M2 release at the end of this month. |
Jay Xu commented Our proj use |
Nick Padgett opened SPR-7114 and commented
Instead of using a command/form object, I bind much of my data to the request body. I expected that I could specify an Errors/BindingResult object after a
@RequestBody
method parameter. Currently, I do the following:I would like to do the following:
However, when I do, I receive the following exception:
Affects: 3.0.2
Attachments:
11 votes, 13 watchers
The text was updated successfully, but these errors were encountered: