Given this object to validate :
class GroovyTestListItemValidation {
List<@NotBlank String> inner = []
GroovyTestListItemValidation(List<String> elements) {
this.inner.addAll(elements)
}
}
Given this (spock) test:
class NotBlankGroovySpec extends Specification{
def "for each collection items with a null, blank or empty"() {
given: "An object to validate"
GroovyTestListItemValidation toBe = new GroovyTestListItemValidation([null," ","","ok"])
when: "Validation is triggered"
Set<ConstraintViolation<?>> constraints = validate(toBe)
then: "3 validation errors are detected"
constraints.size() == 3
}
Set<ConstraintViolation<?>> validate(Object input) {
println("Validating $input")
Set<ConstraintViolation<?>> errs = Validation.buildDefaultValidatorFactory().validator.validate(input)
errs.forEach {
println("${it.propertyPath} ${it.message}")
}
return errs
}
}
The javax.validation constraint : List<@NotBlank String> work fine in java and kotlin (with -Xemit-jvm-type-annotations) but i can't get it working in groovy
Anyone knows a solution please ?
PS: without coding a custom annotation that is already my actual workaround
PS: in kotlin we explicitly ask to keep annotation in bytecode with -Xemit-jvm-type-annotations, i've seen that in the groovy bytecode the annotation is not here, maybe the same trick exists for groovy ?
UPDATE 1: I've found this issue https://issues.apache.org/jira/browse/GROOVY-9632 corrected on groovy 4.
This is a groovy 3.0.4 bug corrected on groovy 4, it's a bad thing for me because i can't upgrade to 4...