TheRock3t
TheRock3t

Reputation: 638

JSR 303 - Name of the annotated field in the custom validator

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

Answers (3)

reconnect
reconnect

Reputation: 336

You can access path via following exp

((ConstraintValidatorContextImpl) context).getConstraintViolationCreationContexts().get(0).getPath()

Upvotes: 3

imaya
imaya

Reputation: 1

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

Upvotes: 0

Gunnar
Gunnar

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

Related Questions