Is there a way to access the target bean from with

2019-05-31 20:05发布

Apart from using class-level validations, is there a way to access the parent bean of a field-level validation annotation from within its validator class?

For example:

public class CustomValidator implements ConstraintValidator<CustomValidation, String> {

    @Override
    public void initialize(final CustomValidation constraintAnnotation) {
    }

    @Override
    public boolean isValid(final String fieldValue, final ConstraintValidatorContext context) {
        // is there a way to access the parent object here?
    }
}

1条回答
你好瞎i
2楼-- · 2019-05-31 20:34

Upon further investigation, it turns out this is not possible with the version 1.1 of the spec.

查看更多
登录 后发表回答