I’ve got some java code that I would like to port to kotlin. It makes heavy use of bean validation annotations. I’ve already run into the limitation of not being able to decorate a field with repeated annotations (see here: Issue with repeated Java 8 annotations), and that is certainly complicating porting the code.
Additionally, the code in question also includes custom annotations to stack validation. For example:
@Documented
@Constraint(validatedBy = {})
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Pattern(regexp = "^(([\\p{Alnum}]([-\\p{Alnum}]*[\\p{Alnum}])?)\\.)*([\\p{Alpha}]([-\\p{Alnum}]*[\\p{Alnum}])?)$")
@ReportAsSingleViolation
public @interface Hostname {
String message() default "Invalid hostname or hostname component";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
In our java code, we regularly decorate fields or getters with annotations such as this as well as @Pattern to enforce multiple regex-based validations (don’t get me started on that). But I’m having trouble getting a kotlin version of this annotation to be picked up by any of the validation enforcement options like spring.
Help?