public static Field findClassField ( Class < ? > beanClass , String fieldName ) { Class < ? > currentClass = beanClass ; while ( currentClass != null && currentClass != Object . class ) { for ( Field field : currentClass . getDeclaredFields ( ) ) { if ( field . isSynthetic ( ) ) { continue ; } if ( field . getName ( ) . equals ( fieldName ) ) { return field ; } } currentClass = currentClass . getSuperclass ( ) ; } return null ; }
Tries to find a class fields . Supports inheritance and doesn t return synthetic fields .