Class ReflectUtils

java.lang.Object
com.vdoc.sdk.commons.utils.ReflectUtils

public class ReflectUtils extends Object
A great utils to simplifie java reflextion
Author:
famaridon
  • Method Details

    • getFieldValue

      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 throw IllegalAccessException.
      Parameters:
      obj - the object to find getter
      field - the field the find getter
      Returns:
      the object instance field value
      Throws:
      IllegalAccessException - on error
      IllegalArgumentException - on error
      InvocationTargetException - on error
    • findGetter

      public static Method findGetter(Object obj, Field field)
      Find the object's field getter. The getter should not have any parameters.
      Parameters:
      obj - the object to find getter
      field - the field the find getter
      Returns:
      the getter if found, else null (not an exception it's simplest to used)
    • getAllFields

      public static <T> List<Field> getAllFields(Class<T> clazz)
      find all class's and super class's fields (with all Modifier)
      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 fields
      mappedAnnotation - the mapped class annotation
      Returns:
      a list with all found fields