Reputation: 23587
I am working on a plugin where i need to integrate Bean Validator with the underlying Framework and it seems to work fine except at one point where i am strucked.
Plugin will take care to provide bridge with any Bean Validator who adhere to JSR303 specifications (Hibernate-Validator,Apache Bean validator)
Once there is some Constraints violation error i need to know what kind of violation it was like was it a
and based on this i need to build Error messages and need to do some other work.
Is there any way to find out the type of Constraints violation from ConstraintViolation<?>
so that i can do post processing to prepare things to display on UI?
Upvotes: 0
Views: 1172
Reputation: 19119
Is there any way to find out the type of Constraints violation from ConstraintViolation so that i can do post processing to prepare things to display on UI?
No there isn't. You can distinguish between class level constraints and property constraints. However, there is no way to determine whether the annotation was placed on the field or the getter of the attribute.
One way to determine between class and property constraint is to look at ConstraintViolation#getPropertyPath(). If getName() returns null on the leaf node you have a class level constraint, otherwise a property level constraint.
In Bean Validation 1.1 (JSR 349) things get a little easier, because the Path returned by ConstraintViolation#getPropertyPath() contains for each node a #getElementDescriptor. Still no way to distinguish how the attribute is accessed (field vs getter).
Upvotes: 2