-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
DefaultErrorAttributes doesn't populate errors for MethodValidationResult #42013
Comments
This was (somewhat) intentional as we wanted to be confident that the error was suitable for serializing to JSON. Filtering things so that only |
As an Actually the example in spring-projects/spring-framework#32396 (comment) would cause it.
|
Thanks for the additional details but I'd really like to see a complete, minimal sample that reproduces this. Can you please provide one? |
Here's a minimal sample. I based it on Spring Boot 3.3.3.
The tests do not use MockMvc on purpose as otherwise the error controller would never be called. |
I'm wondering if we should create our own wrapper object for serialization and try to support the |
We discussed this today and would like to add a wrapper object. This will be a slight breaking change and the Javadoc of |
Can i contribute? |
Absolutely @YongGoose, that would be most welcome. We won't be able to merge it for 3.4 but it can be a 3.5 enhancement. |
Closing in favor of PR #43330. Thanks @YongGoose |
GH-39865 added support for
MethodValidationResult
toDefaultErrorAttributes
but it filters the list errors published in the result and used for counting to instances ofObjectError
.With a method signature (in a RestController) of e.g.
public void method(@PathVariable @Pattern(regexp = "^a.*") String parameter)
, this results inmessage = "Validation failed for method='public void <class>.method(java.lang.String)'. Error count: 0"
errors = []
This is due to the fact, that the
MethodValidationResult
generated byMethodValidationAdapter
will contain instances ofParameterValidationResult
that have resolvable errors of typeDefaultMessageSourceResolvable
(and notObjectError
).Spring Boot 3.3.1
Spring Framework 6.1.10
The text was updated successfully, but these errors were encountered: