Hi Luca,
there is something related in HV 4.2 (currently released as Beta version) which might help you. There you can create composed constraints which's base constraints are joined by a logical OR:
Code:
@ConstraintComposition(OR)
@Size(min = 11, max = 11)
@Size(min = 16, max = 16)
@ReportAsSingleViolation
@Target({ METHOD, FIELD })
@Retention(RUNTIME)
@Constraint(validatedBy = { })
public @interface CodiceFiscale {
String message() default "codicefiscale.errorkey";
Class<?>[] groups() default { };
Class<? extends Payload>[] payload() default { };
}
That said you might consider to model person and corporate with separate classes and annotate each code fiscale member with the appropriate size constraint.
Hth,
Gunnar