This is a good question. JSR 303 Bean The validation specification describes the verification procedure in section 3.5.
For this group, the verification procedure that applies to this Bean instance is applied for verification; it is expected to fulfill the following validation restriction in an arbitrary order:
- for all reachable fields, perform all field-level checks (including those expressed in superclasses) corresponding to the target group, if this check constraint has not already been processed during this check procedure for a given navigation path (see section 3.5.1) as part of a previous group match.
...
The object verification procedure is described as such. For each declaration of restriction:
- define, for the declaration of constraint, the appropriate ConstraintValidator to use (see section 3.5.3)
- perform the isValid operation (from the implementation of the compliance check) on the relevant data (see section 2.4).
- if isValid returns true, go to the next restriction,
- If isValid returns false, the Bean Validation provider populates the ConstraintViolation object according to the rules defined in section 2.4 and adds these objects to the list of constraint violations.
In your case, you are dealing with checking a simple String
field, where the target group is Default
. You have two validation restrictions (@AlphanumericString and @Size), which, according to the documentation, will be checked / processed separately in a specific order.
So, to answer your question. No, when using @Size
extray no override will be applied to your @AlphanumericString
. To achieve what I think you are trying to do, you can create a set of constraints where you redefine attributes from compositions of such annotations:
@Pattern(regexp="[a-zA-Z]*") @Size @Constraint(validatedBy = AlphanumericStringValidator.class) @Documented @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) @Retention(RUNTIME) public @interface AlphanumericString { // ... @OverridesAttribute(constraint=Size.class, name="min") int min() default 3 @OverridesAttribute(constraint=Size.class, name="max") int max() default 230; // ... }
and use it like this:
@AlphanumericString(min = 100, max = 150)
nowaq
source share