Get Name of Annotated Field in Jakarta ConstraintValidator Implementation

41 Views Asked by At

Is it possible to get the name of the field onto which a custom validation annotation has been placed within the ConstraintValidator? Consider the following:

@MyConstraint
String state ;
public class MyConstraintValidator implements ConstraintValidator<MyConstraint, String> { ... }

How can I get the field name of 'state' within the ConstraintValidator? (That field name will be used in the validation itself.)

In the debugger, I'm able to see it on the ConstraintValidatatorContextImpl basePath, but I'd rather not cheat by casting it up.

0

There are 0 best solutions below