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
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
You can access path via following exp
((ConstraintValidatorContextImpl) context).getConstraintViolationCreationContexts().get(0).getPath()
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()
).
In hibernate implementation, You can get it using reflection ConstraintValidatorContext.basePath.currentLeafNode.name