dimanche 24 février 2019

Is it possible to get "Applied" method from an annotation?

I am trying to add new cross-parameters validation annotation with Hibernate validator 5(JSR 349, Bean Validation 1.1) under Java8. My ideal use case is like below.

@UpdateValidation
public void update(@After toObj, @Before fromObj, anything else...)

However I am not sure if it is possible to distinguish the two objects(@After and @Before) when implementing ConstraintValidator. Please check below code, I feel the chance is to get the indexes of parameters within initialize method but cannot figure a way to do it with Java Reflection API.

public class TestValidator implements
                       ConstraintValidator<UpdateValidation, Object[]>
{

@Override
public void initialize (UpdateValidation constraintAnnotation)
{
    // Is it possible to get the indexes 
    // of parameters with @Before and @After here?

}

@Override
public boolean isValid (Object[] values, ConstraintValidatorContext context)
{

    return false;
}

}





Aucun commentaire:

Enregistrer un commentaire