开发者

Hibernate Validator 4+. Get all Constraints associated with a class

How can I get all constraints for a class. For instance I have

class A {
   @NotNull
   private SomeBean field;
}

When I call:

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator(); 
Set<ConstraintDescriptor<?>> descriptor =  validator.getConstraintsForClass(formClass).getConstraintDescriptors();

The set is empty. I would assume there is already some functionality in Hibernate Validator that would give me all the information about constraints in a neat way , without me having开发者_C百科 to resort to the reflection api.


getConstraintsForClass() returns constraints on the class itself. To get constraints on properties, you should call getConstrainedProperties().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜