lundi 23 juillet 2018

How do I get the real annotation instead of a proxy from ConstraintViolation::getAnnotation? (javax.validation Apache Bval)

I'm trying to get a Class object reference for the annotation which caused a ConstraintViolation in the javax.validation package (Apache Bval implementation).

After getting some ConstraintViolations, I pass them into the following function:

private Class<?> getConstraintAnnotation(final ConstraintViolation<?> constraintViolation) {
    return constraintViolation
        .getConstraintDescriptor()
        .getAnnotation()
        .getClass();
  }

And this returns a class object whose getName(), getCanonicalName(), and getTypeName() all return "java.lang.reflect.Proxy".

Weirdly enough, the toString() method of the Class object returns back "class com.sun.proxy.$Proxy10".

Is there a way for me to get the real annotation classes and not these proxies? I would ideally like to map the built-in annotations to error codes (without having to overwrite the message every time I use it).





Aucun commentaire:

Enregistrer un commentaire