Reputation: 638
I have a question about custom annotations. More precisely, do I have access to the name of the annotated field inside the custom validator ? If yes, how do I access this?
Thanks
Upvotes: 2
Views: 3249
Reputation: 336
You can access path via following exp
((ConstraintValidatorContextImpl) context).getConstraintViolationCreationContexts().get(0).getPath()
Upvotes: 3
Reputation: 1
In hibernate implementation, You can get it using reflection ConstraintValidatorContext.basePath.currentLeafNode.name
Upvotes: 0
Reputation: 18990
No, you can't access the name of the validated element from within a constraint validator. It is exposed by the resulting constraint violation, though (via getPropertyPath()
).
Upvotes: 0