-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Method validation is not triggered when constraints are applied to the elements of a List #31870
Comments
This looks similar to #31746 |
I would say no, unless I have misunderstood the other issue. |
At present you need @GetMapping
public String get(@RequestParam(required = false) List<@NotBlank String> list) {
// ...
} Given that we do make a decision whether method validation applies to a given controller method, we should enhance checks to include the above, which is supported by bean validation. |
Prior to this commit, #31870 added support for constraint annotations on container elements for handler method argument validation. Supporting this use case: ``` public void addNames(List<@notempty String> names) ``` This commit does the same for `@Valid` annotation: ``` public void addPeople(List<@Valid Person> people) ``` Fixes gh-32964
In Spring Boot 3.2.0 it seems method validation is not always happening as expected, if the constraint is on list elements only. It can be worked around by applying
@Valid
or a@Constraint
to the list, or by having another argument for the endpoint which has a@Constraint
, but otherwise it seems to miss them.I have attached a small demo project to illustrate it. I would expect all of the test cases to be a success, but the one with only a
@Constraint
applied to the list elements fails.I haven't tested if the parameter is for example a map (if it is even possible in this context), but my guess is it has the same issue.
Spring Boot version: 3.2.0
Java version: OpenJDK 19 (19+36-2238)
demo.zip
The text was updated successfully, but these errors were encountered: