code: public static Field[] getAllFields(Class<?> clazz) {
          if (clazz == null) {
              throw new IllegalArgumentException("You must specify the class that contains the fields");
          }
          Set<Field> fields = new LinkedHashSet<Field>();
  
          Class<?> thisType = clazz;
  
          while (thisType != null) {
              final Field[] declaredFields = thisType.getDeclaredFields();
              for (Field field : declaredFields) {
                  field.setAccessible(true);
                  fields.add(field);
              }
              thisType = thisType.getSuperclass();
          }
          return fields.toArray(new Field[fields.size()]);
      }
docs: Get all fields in a class hierarchy! Both declared an non-declared (no
  duplicates).
  
  @param clazz The class whose fields to get.
  @return All fields declared in this class hierarchy.