in SlingModelPersist/src/main/java/org/apache/sling/models/persistor/impl/util/ReflectionUtils.java [313:339]
public static Object getAnnotatedValue(Object obj, Class annotatedType) {
if (obj == null) {
return null;
}
Annotation a = obj.getClass().getAnnotation(annotatedType);
try {
if (a != null) {
String value = (String) MethodUtils.invokeMethod(a, "value");
if (value != null && !value.isEmpty()) {
return value;
}
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
// Do nothing, it didn't have a value defined on that annotation
}
List<Field> fields = FieldUtils.getFieldsListWithAnnotation(obj.getClass(), annotatedType);
try {
if (fields == null || fields.isEmpty()) {
List<Method> methods = MethodUtils.getMethodsListWithAnnotation(obj.getClass(), annotatedType);
return CollectionUtils.isNotEmpty(methods) ? methods.get(0).invoke(obj) : null;
} else {
return fields.get(0).get(obj);
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
return null;
}
}