-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Built-in method validation validates @RequestBody parameter twice #31711
Comments
How did you come to this conclusion? |
I can somewhat confirm this same behavior, but for a different reason. (Spring Boot 3.1.3, but this is Spring Framework level behavior) The following Controller does reproduce the issue I'm describing. It appears the @Validated
@RestController
@RequestMapping("/rest/test")
public class TestController {
public record MyData(String foo, @NotNull String bar) {}
@PostMapping("/list")
public String sayHello(@Valid @RequestBody @NotEmpty List<@Valid MyData> myList) {
return "Hello";
}
@PostMapping
public String sayWorld(@Valid @RequestBody @NotNull MyData myData) {
return "World";
}
} Sending in the following to [
{ "bar": null, "foo" : "buzz" }
] Where sending this to the {"bar": null, "foo": "buzz"} I'm not 100% confident in the degree this Exception difference and the Double validation are related, but it does feel like they lay on a similar issue. |
@snicoll And, attached partial stack traces
|
@giger85 this is not expected, but I will need to debug to find out more. Do you have a small sample? |
@Crain-32 your case is a little different. First you have a class-level |
I was able to confirm the issue. It's related to the Spring Boot @Crain-32 for your case you only need to remove |
@rstoyanchev |
Version
Situation
I tested below spring MVC rest controller and model. (use kotlin)
And call api and debug.
Then, the validation of
age
field occurs twice.Is this behavior valid?
Related code
In
invokeForRequest
method, executedgetMethodArgumentValues
method first and thenmethodValidator.applyArgumentValidation
method.If requestBody is validate object and built-in method validation is activated, then request body object is validated twice.
spring-framework/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java
Line 171 in 61be452
spring-framework/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java
Line 178 in 61be452
The text was updated successfully, but these errors were encountered: