Here is an ability to arrange multiple constraints into the single constraint such as below:
@NotNull @Size(min = 2, max = 14) @CheckCase(CaseMode.UPPER) @Target({ METHOD, FIELD, ANNOTATION_TYPE }) @Retention(RUNTIME) @Constraint(validatedBy = { }) @Documented public @interface ValidLicensePlate {
String message() default "{org.hibernate.validator.referenceguide.chapter06." + "constraintcomposition.ValidLicensePlate.message}";
Class<?>[] groups() default { };
Class<? extends Payload>[] payload() default { }; }
In this case annotations @NotNull, @Size and @CheckCase will be processed as a single @ValidLicensePlate constraint. But the execution order of @NotNull, @Size and @CheckCase annotations can not be defined and sometimes it breaks validator by throwing exception. I've found that this bug is inside of a constructor of the org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree class. Child constraints can be sorted by groups such top level constraints. |
|