Closed
Description
Version
- spring framework: 6.1.1 (spring boot 3.2.0)
Situation
I tested below spring MVC rest controller and model. (use kotlin)
@RestController
@RequestMapping(value = ["/api"])
class FooController {
@PostExchange("/foo")
fun createFoo(
@RequestBody @Valid myData: MyData,
@Min(1) @RequestParam("hint") hint: Int
): Map<String, Any?> {
return mapOf("myData" to myData)
}
}
data class MyData(
val name: String,
@get:Min(1)
val age: Int
)
And call api and debug.
> curl -X POST \
-H 'Content-Type: application/json' \
'http://localhost:8080/api/foo?hint=2' \
-d '{"name": "foo-1", "age": 3}'
Then, the validation of age
field occurs twice.
Is this behavior valid?
Related code
In invokeForRequest
method, executed getMethodArgumentValues
method first and then methodValidator.applyArgumentValidation
method.
If requestBody is validate object and built-in method validation is activated, then request body object is validated twice.