Пишу кастом javax.validation.ConstraintValidator
.Я хотел бы добавить собственный путь к свойству ConstraintViolation
, включая путь родительского свойства.Итак:
class BaseClass {
@Valid MyProperty first;
}
@MyValidator class MyProperty {
String someField;
}
class MyValidatorImpl implements ConstraintValidator<MyValidator, MyProperty> {
// ...
public boolean isValid(MyProperty value, ConstraintValidatorContext context) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("My message")
// How to access the parent property name "first" here?
.addPropertyNode("my custom property")
.addConstraintViolation()
}
}
Любая помощь будет оценена.