vendredi 3 novembre 2017

Getting java constaint annotations using reflection

I would like to iterate some JAXB objects which are annotated with constraint validation annotations and retrieve the annotations programmatically through reflection . I have tried using the following code:

PropertyUtilsBean pub= new PropertyUtilsBean();
    PropertyDescriptor[] pds = pub.getPropertyDescriptors(object);

    for (PropertyDescriptor pd : pds) {
        Class<?> propClazz = pd.getPropertyType();
        Annotation[] annotations = propClazz.getDeclaredAnnotations();
        for(Annotation a : annotations) {
            System.out.println(a.toString());
        } 

However I can only get annotations define by the JAXB object, for example @XmlType, etc. Has anyone any suggestion please?





Aucun commentaire:

Enregistrer un commentaire