Skip to content
Permalink
Browse files
permit overriding of built-in constraint validators per paragraph 2 o…
…f BV spec v2 section 8
  • Loading branch information
mbenson committed Oct 16, 2018
1 parent 963ac52 commit 3f67257d0c36db53d6e9b807cc9d65b1263d001c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
@@ -139,9 +139,6 @@ private ValidatorMappingProvider createValidatorMappingProvider() {
}
configured = new DualValidationMappingProvider(AnnotationDeclaredValidatorMappingProvider.INSTANCE, custom);
}
// interpret spec as saying that default constraint validators are
// always present even when annotation-based validators
// have been excluded by custom (i.e. XML) config:
return new DualValidationMappingProvider(configured, ConstraintDefaults.INSTANCE);
return new DualValidationMappingProvider(ConstraintDefaults.INSTANCE, configured);
}
}
@@ -35,16 +35,16 @@ public DualValidationMappingProvider(ValidatorMappingProvider primary, Validator
protected <A extends Annotation> ValidatorMapping<A> doGetValidatorMapping(Class<A> constraintType) {

final ValidatorMapping<A> secondaryMapping = secondaryDelegate.doGetValidatorMapping(constraintType);
final ValidatorMapping<A> primaryMapping = primaryDelegate.doGetValidatorMapping(constraintType);
if (secondaryMapping == null) {
return primaryDelegate.doGetValidatorMapping(constraintType);
return primaryMapping;
}
final AnnotationBehavior annotationBehavior = secondaryMapping.getAnnotationBehavior();

if (annotationBehavior == AnnotationBehavior.EXCLUDE) {
if (primaryMapping == null || annotationBehavior == AnnotationBehavior.EXCLUDE) {
return secondaryMapping;
}
return ValidatorMapping.merge(
Arrays.asList(primaryDelegate.doGetValidatorMapping(constraintType), secondaryMapping),
return ValidatorMapping.merge(Arrays.asList(primaryMapping, secondaryMapping),
AnnotationBehaviorMergeStrategy.consensus());
}
}

0 comments on commit 3f67257

Please sign in to comment.