Package com.vdoc.sdk.commons.utils
Class ReflectUtils
java.lang.Object
com.vdoc.sdk.commons.utils.ReflectUtils
A great utils to simplifie java reflextion
- Author:
- famaridon
-
Method Summary
Modifier and TypeMethodDescriptionstatic MethodfindGetter(Object obj, Field field) Find the object's field getter.getAllFields(Class<T> clazz) find all class's and super class's fields (with allModifier)getAllFields(Class<T> clazz, Class<? extends Annotation> mappedAnnotation) get all class's fields and all mapped supper class.static ObjectgetFieldValue(Object obj, Field field) this method get the field value by using great java reflexion.
-
Method Details
-
getFieldValue
public static Object getFieldValue(Object obj, Field field) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException this method get the field value by using great java reflexion. First of all we search for a public getter, if no one found we check for field public accessibility.
if nothing works we throwIllegalAccessException.- Parameters:
obj- the object to find getterfield- the field the find getter- Returns:
- the object instance field value
- Throws:
IllegalAccessException- on errorIllegalArgumentException- on errorInvocationTargetException- on error
-
findGetter
Find the object's field getter. The getter should not have any parameters.- Parameters:
obj- the object to find getterfield- the field the find getter- Returns:
- the getter if found, else null (not an exception it's simplest to used)
-
getAllFields
find all class's and super class's fields (with allModifier)- Parameters:
clazz- the class to get all fields- Returns:
- a list with all found fields
-
getAllFields
public static <T> List<Field> getAllFields(Class<T> clazz, Class<? extends Annotation> mappedAnnotation) get all class's fields and all mapped supper class. A mapped super class must be annoted with mappedSupperAnnotation.- Parameters:
clazz- the class to get all fieldsmappedAnnotation- the mapped class annotation- Returns:
- a list with all found fields
-