开发者

Constraint Validation

I am using javax.validation.Validator and relevant classes for annotation based validation.

Configuration<?> configuration = Validation.byDefaultProvider().configure();   
ValidatorFactory factory = configuration.buildValidatorFactory();   
Validator validator = factory.getValidator(); 

Set<ConstraintViolation<ValidatableObject>> constraintViolations = validator.validate(o);   
for (ConstraintViolation<ValidatableObject> value : constraintViolations) {   
     List< Class< ? extends ConstraintValidator< ? extends Annotation,?>>> list = 
             value.getConstraintDescriptor().getConstraintValidatorClasses();  
}

I get a compilation error stating:

Type mismatch: cannot convert from List< Class< ? extends Constr开发者_JS百科aintValidator< capture#4-of ?,?>>> to List< Class< ? extends ConstraintValidator< ? extends Annotation,?>>>

What am I missing?


If you don't mind are working with ConstraintValidator<?, ?> (ie you don't need ConstraintValidator<? extends Annotation, ?>), this should work:

Configuration<?> configuration = Validation.byDefaultProvider().configure();   
ValidatorFactory factory = configuration.buildValidatorFactory();   
Validator validator = factory.getValidator(); 

Set<ConstraintViolation<ValidatableObject>> constraintViolations = validator.validate(o);   
for (ConstraintViolation<ValidatableObject> value : constraintViolations) {   
     List< Class< ? extends ConstraintValidator<?,?>>> list = 
             value.getConstraintDescriptor().getConstraintValidatorClasses();  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜