2

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

TheRock3t
  • 628
  • 9
  • 22

3 Answers3

3

You can access path via following exp

((ConstraintValidatorContextImpl) context).getConstraintViolationCreationContexts().get(0).getPath()
reconnect
  • 306
  • 3
  • 13
0

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()).

Gunnar
  • 18,095
  • 1
  • 53
  • 73
0

In hibernate implementation, You can get it using reflection ConstraintValidatorContext.basePath.currentLeafNode.name

imaya
  • 1
  • 1