我想迭代一些使用约束验证注释注释的JAXB对象,并通过反射以编程方式检索注释。我尝试使用以下代码:
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());
}
但是我只能通过JAXB对象获取注释,例如@XmlType等。有没有人有任何建议?