I\'ve created a composite annotation that consists of @Digits and @Min
@Digits(integer=12, fraction=0)
@Min(value=0)
@ReportAsSingleViolation
@Documented
@Re
You could make use of @OverridesAnnotation:
@Digits(integer=0, fraction=0)
@Min(value=0)
@ReportAsSingleViolation
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target( { FIELD, METHOD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Constraint(validatedBy={})
public @interface PositiveInteger {
String message() default "{positive.int.msg}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
@OverridesAttribute(constraint=Digits.class, name="integer")
int digits();
}
That way the value given in @PositiveInteger#digits()
will be propagated to @Digits
.