@Valid is not working with @PutMapping where Request Body is List of dataclass in Kotlin Spring boot
have added the library for it in the gradle.build.kts
implementation("org.springframework.boot:spring-boot-starter-validation")
then tested for the below scenario it worked
@PutMapping(@Valid @RequestBody upsertData: UpsertData): ResponseEntity<String> {
}
data class UpsertData {
@field:NotBlank(message = "Name must not be blank")
val naName: String,
@field:Min(value = 18, message = "Age must be at least 18")
val age: Int
}
but when I tried for below it is not validating the input
@PutMapping(@Valid @RequestBody upsertData: List<UpsertData>): ResponseEntity<String> {
}
I also tried by adding @Valid for the dataclass only but still this is failing...
@PutMapping(@Valid @RequestBody upsertData: List<@Valid UpsertData>): ResponseEntity<String> {
}
Can someone please help me here...
try following because Kotlin declaritve is not same as Java;