Cannot validate List within Kotlin's data class

Description

The validation for `List<@Size(min = 1) String>` is not working in Kotlin.

data class Pet( @get:Size(min = 1, max = 16) val name: String, @get:Valid // @Size parameter seems to be ignored val labels: List<@Size(min = 1, max = 16) String>, ) fun main() { val validator = Validation .byDefaultProvider() .configure() .messageInterpolator(ParameterMessageInterpolator()) .buildValidatorFactory() .validator // correctly fails with: [ConstraintViolationImpl{interpolatedMessage='size must be between 1 and 16', propertyPath=name, rootBeanClass=class net.goout.entitystorage.services.Pet, messageTemplate='{javax.validation.constraints.Size.message}'}] println(validator.validate(Pet(name = "", labels = listOf("Naughty")))) // false negative, should fail, returns: [] println(validator.validate(Pet(name = "Jane", labels = listOf(""))))}

See the comments in the code above.

Environment

None

Activity

Show:

Details

Assignee

Reporter

Labels

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

Vojtěch Knyttl

Affects versions

Priority

Created October 26, 2021 at 4:24 PM
Updated December 10, 2024 at 12:14 PM

Flag notifications