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)
Comment From: bclozel
This looks similar to https://github.com/spring-projects/spring-framework/issues/31746 Can you have a look and let us know?
Comment From: mcso
I would say no, unless I have misunderstood the other issue.
The issue isn't the path is incorrect, it is that the (in this example) @NotBlank
validation is not done for entries in the string list.
Comment From: rstoyanchev
At present you need @Valid
with a List
method parameter, and we don't for example detect constraints on elements of a container. For example:
@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.