/** * Returns all fields defined by this class or one of its superclasses. This includes public, protected and * private fields. * * @param clazz the class to collect the fields for * @return a list of all defined fields of the given class and its superclasses (excluding {@code Object}) */ @Nonnull public static List<Field> getAllFields(@Nonnull Class<?> clazz) { DataCollector<Field> collector = new DataCollector<>(); try { walkHierarchy(clazz, value -> collector.addAll(Arrays.asList(value.getDeclaredFields()))); } catch (Exception e) { Exceptions.handle(e); } return collector.getData(); }