public static List < Field > getClassFields ( Class < ? > beanClass ) { Map < String , Field > resultMap = new HashMap <> ( ) ; LinkedList < Field > results = new LinkedList <> ( ) ; Class < ? > currentClass = beanClass ; while ( currentClass != null && currentClass != Object . class ) { for ( Field field : currentClass . getDeclaredFields ( ) ) { if ( ! field . isSynthetic ( ) ) { Field v = resultMap . get ( field . getName ( ) ) ; if ( v == null ) { resultMap . put ( field . getName ( ) , field ) ; results . add ( field ) ; } } } currentClass = currentClass . getSuperclass ( ) ; } return results ; }
Returns a list of class fields . Supports inheritance and doesn t return synthetic fields .