Add explanation for @Valid container parameters in ann-validation.adoc#35186
Add explanation for @Valid container parameters in ann-validation.adoc#35186HeeChanN wants to merge 1 commit intospring-projects:mainfrom
Conversation
Added a section explaining that container parameters annotated with `@Valid` Signed-off-by: Hee Chan <ahc70032@gmail.com>
| likewise subject to method validation. They are detected by | ||
| `HandlerMethod.MethodValidationInitializer.checkArguments(…)`, and any | ||
| resulting constraint violations cause a `HandlerMethodValidationException` | ||
| to be raised. |
There was a problem hiding this comment.
Is @RequestBody List<Foo> items really validated? I would expect it needs @Valid.
What is the purpose of having @Valid in both places with @RequestBody @Valid List<@Valid Foo> items? Isn't @RequestBody @Valid List<Foo> items sufficient, or likewise I would expect @RequestBody List<@Valid Foo> items to work. It's unclear why both?
There was a problem hiding this comment.
Thanks for catching that! I actually made a typo in my description — I meant to write either
@RequestBody @Valid List<Foo> items or @RequestBody List<@Valid Foo> items.
It was my mistake to put both annotations together in the example. Thanks for pointing it out!
For context, the reason I opened this PR is that when using @Valid together with a container type,
I noticed that @RequestBody @Valid List<Foo> triggers a HandlerMethodValidationException,
whereas the official documentation led me to expect a MethodArgumentNotValidException.
I thought it would be helpful to clarify this behavior in the reference documentation so that others won’t run into the same confusion.
There was a problem hiding this comment.
Thanks for clarifying. Now that the intent is more clear, I am going to address this differently, and that section generally can use a little improvement.
|
Superseded by #35759. |
Added a section explaining that container parameters annotated with
@Valid