public static Object getProp ( Object object , final String property ) { if ( object == null ) { return null ; } if ( isDigits ( property ) ) { /* We can index numbers and names. */ object = idx ( object , StringScanner . parseInt ( property ) ) ; } Class < ? > cls = object . getClass ( ) ; /** Tries the getters first. */ Map < String , FieldAccess > fields = Reflection . getPropertyFieldAccessors ( cls ) ; if ( ! fields . containsKey ( property ) ) { fields = Reflection . getAllAccessorFields ( cls ) ; } if ( ! fields . containsKey ( property ) ) { return null ; } else { return fields . get ( property ) . getValue ( object ) ; } }
This is one is forgiving of null paths . This works with getters first i . e . properties .