0

I have dto object with field of Boolean? type which is used in controller. Annotation @get:NotNull(message = "{err.test}") does not have any affect when I pass isCharity = null.

data class Human { 
  @get:NotNull(message = "{err.test}")
  val isCharity: Boolean?
}

@RestController
internal class TestController {

  @PutMapping
  fun upsert(@RequestBody @Valid input: Human)...
}

Could you explain me why is that and how I can validate it?

A.Sidor
  • 257
  • 4
  • 12
  • Related? https://stackoverflow.com/questions/64002548/what-does-getnotnull-mean-in-kotlin – dnault Sep 26 '22 at 17:05
  • 1
    That's a very strange annotation. Like, if you don't want to allow null, why not declare the property as non-nullable `Boolean` instead of nullable `Boolean?` ? Did this come out of a code generator? – dnault Sep 26 '22 at 17:07
  • 1
    Because in case of Boolean there will be default value = false when null is passed – A.Sidor Sep 26 '22 at 17:17

0 Answers0