code: public static List<Field> getAllDeclaredFields(Object object) {
          List<Field> allFields = new ArrayList<>();
          Class<?> objClass = object.getClass();
          
          // Loop through the class hierarchy
          while (objClass != Object.class) {
              allFields.addAll(Arrays.asList(objClass.getDeclaredFields()));
              
              objClass = objClass.getSuperclass();
          }
  
          allFields.removeIf(Field::isSynthetic);
          allFields.forEach(f -> f.setAccessible(true));
          
          return allFields;
      }
docs: Returns all fields of any scope, throughout the class hierarchy of the object, excluding
  synthetic fields (like references to outer classes). All returned fields have accessibility
  override flag set.