Skip to content
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

Improve method validation support for errors on elements within a container #31530

Closed
wants to merge 1 commit into from

Conversation

k-seth
Copy link
Contributor

@k-seth k-seth commented Nov 1, 2023

Expands on the validation behaviour added as part of the work for #30645, motivated by an issue with Sets containing an object with nested Lists, introduced in #29825. The adapter should now better handle nested objects for types beyond those of List or Map.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 1, 2023
@rstoyanchev rstoyanchev self-assigned this Nov 1, 2023
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 1, 2023
@rstoyanchev rstoyanchev added this to the 6.1.0 milestone Nov 1, 2023
@rstoyanchev rstoyanchev changed the title Expand support for adapting container type violations Improve method validation support for errors on elements within a container Nov 1, 2023
@rstoyanchev
Copy link
Contributor

For additional context, see #30645 (comment). In short, currently we support List and Map containers. The goal is to also support arrays and sets, and other container types for which there is a registered Jakarta ValueExtractor.

@rstoyanchev
Copy link
Contributor

Thanks for the report and changes. Element container handling is not only improved but also simpler.

rstoyanchev added a commit that referenced this pull request Dec 18, 2023
Method validation needs to be used for a container such as a List or
Map, but until now we were only checking for a List container.
Moreover, in gh-31530 we improved method validation to also cover
any Collection.

This change aligns with HandlerMethod check for when method validation
applies with the underlying ability of method validation.
rstoyanchev added a commit that referenced this pull request Dec 20, 2023
The goal for #31530 was to support bean validation on Set and other
method parameters that are containers of value(s) for which there is
a registered Jakarta Validation ValueExtractor.

Unfortunately, bean validation does not expose the unwrapped value
for a Path.Node, which we need for a method parameter in order to
create a BindingResult for the specific bean within the container,
and the leafBean that we tried to use is really the node at the
very bottom of the property path (i.e. not what we need).

This change removes the use of beanLeaf, restores the logic as it
was before, adds support for arrays, and a new test class for
scenarios with cascaded violations.

See gh-31746
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants