Anyone familiar with validation using JSR-303 anno...
# announcements
j
Anyone familiar with validation using JSR-303 annotations ? I'm not sure if this is Kotlin related but I'm having difficulties defining my annotations using interface EDIT: Workaround is to use @JvmDefault on interface method
For example if I have interface
Copy code
interface Foo {
    @AssertTrue
    fun isValid() = true
}
And bean
Copy code
class FooBean: Foo
now validator.validate(FooBean()) causes two calls to isValid() function and I'm not sure why this is happening
f
which validation library are you using and how are you creating the
validator
instance?
j
Spring injected Validator -bean but I can try using Validation.buildDefaultValidatorFactory().validator directly too which I think is still used under hood for Spring Validator
does not seem to make a difference, both using Hibernate ValidatorImpl under the hood
f
mmm ok
j
Debugging implementation leads me to two MetaConstraint-instances
both have propertyName=valid
other has declaringClass=Foo
and the other one declaringClass=FooBean
so why the metadata model has both
f
you could try asking in #C0B8ZTWE4 if anyone's had that issue, I've used Hibernate Validator a bunch but in Dropwizard and don't recall ever having this happen
r
@Jukka Siivonen there is an alternative to Bean Validation: https://github.com/valiktor/valiktor. With Valiktor, you can write your validations using a DSL instead of annotations 🙂
j
Thanks for suggestion, I submitted this question in Hibernate Validator forums https://discourse.hibernate.org/t/interface-validation-is-ran-twice-kotlin/2584
I have included decompiled Kotlin code in post above, maybe it can give some hints...
Using @JvmDefault on interface method seems to fix this issue
sounds like an ugly workaround 😞