Spring webflux bean check not working

I am trying to use bean validation in Webflux. This is what I have so far:

@PostMapping("contact")
fun create(@RequestBody @Valid contact: Mono<Contact>) : Mono<Contact> {
    return contact.flatMap { contactRepository.save(it) }
            .doOnError{ Error("test") }
}

The validation does not work ... I would expect it to display Error("test")...

Does anyone have a working example (Java or Kotlin)?

UPDATE

Here is the repository so that it can be played: https://github.com/jwz104/webflux-validation-test

Request:

curl --request POST \
  --url http://localhost:8080/tickets \
  --header 'content-type: application/json' \
  --data '{
    "email": "",
    "name": "",
    "message": ""
}'

Renamed contact to ticket, but everything still remains the same.

+6
source share
2 answers

, , Ticket. Spring . Kotlin, .

Ticket :

data class Ticket(
        @field:Id
        @field:JsonSerialize(using = ToStringSerializer::class)
        val id: ObjectId = ObjectId.get(),

        @field:Email
        @field:Max(200)
        @field:NotEmpty
        val email: String,

        @field:NotEmpty
        @field:Size(min = 2, max = 200)
        val name: String,

        @field:NotEmpty
        @field:Size(min = 10, max = 2000)
        val message: String
)

, , , :

@PostMapping("tickets")
fun create(@RequestBody @Valid contact: Mono<Ticket>) : Mono<Ticket> {
    return contact.flatMap { ticketRepository.save(it) }
            .doOnError{ Error("test") }
}
+2

bindingResult: BindingResult . , - bindingResult.isValid(). , .

+1

All Articles