Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ directly on method parameters, or on the method (for the return value), then met
validation must be applied, and that supersedes validation at the method argument level
because method validation covers both method parameter constraints and nested constraints
via `@Valid`. The exception raised in this case is `HandlerMethodValidationException`.
+
Container parameters annotated with `@Valid`—for example,
`@RequestBody List<Foo> items` or `@RequestBody @Valid List<@Valid Foo> items`—are
likewise subject to method validation. They are detected by
`HandlerMethod.MethodValidationInitializer.checkArguments(…)`, and any
resulting constraint violations cause a `HandlerMethodValidationException`
to be raised.
Copy link
Contributor

@rstoyanchev rstoyanchev Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Author

@HeeChanN HeeChanN Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


Applications must handle both `MethodArgumentNotValidException` and
`HandlerMethodValidationException` as either may be raised depending on the controller
Expand Down