I searched for solutions to validate data models in spring in Kotlin. But am not able to.
The following is the Tag data class
.
data class Tag(@field:NotNull var name: String) {
lateinit @Id var id: ObjectId
}
I have enabled the configuration to use bean validation
@Configuration
open class ValidatorConfig {
@Bean
open fun validator() = LocalValidatorFactoryBean()
}
As per my knowledge, Spring Boot loads all the Bean Configuration automatically. And at runtime, when POSTed with empty Json, proper validation error should have been thrown but the following error is thrown
Instantiation of [simple type, class kagaz.sano.model.Tag] value failed for
JSON property name due to missing (therefore NULL) value for creator parameter
name which is a non-nullable type\n at [Source:
org.apache.catalina.connector.CoyoteInputStream@66f3b65c; line: 3, column: 1]
(through reference chain: kagaz.sano.model.Tag[\"name\"])