Skip to content

Conversation

@HeeChanN
Copy link

Added a section explaining that container parameters annotated with @Valid

Added a section explaining that container parameters annotated with `@Valid`

Signed-off-by: Hee Chan <[email protected]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 11, 2025
@rstoyanchev rstoyanchev self-assigned this Nov 4, 2025
@rstoyanchev rstoyanchev added type: documentation A documentation task in: web Issues in web modules (web, webmvc, webflux, websocket) labels Nov 4, 2025
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.

@rstoyanchev
Copy link
Contributor

Superseded by #35759.

@rstoyanchev rstoyanchev closed this Nov 5, 2025
@rstoyanchev rstoyanchev added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: documentation A documentation task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants