@Test public void testFindGetter() throws Exception { final String name = "Bob"; bean.setName(name); assertEquals(name, findGetter(bean, "name").invoke(bean)); }
public static Method findGetter(final Object object, final String fieldName) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } final Class<?> clazz = object.getClass(); final String standardGetterName = getMethodNameForField(GET_PREFIX, fieldName); Method getter = findGetterWithCompatibleReturnType(standardGetterName, clazz, false); if( getter == null ) { final String booleanGetterName = getMethodNameForField(IS_PREFIX, fieldName); getter = findGetterWithCompatibleReturnType(booleanGetterName, clazz, true); } if( getter == null ) { throw new SuperCsvReflectionException( String .format( "unable to find getter for field %s in class %s - check that the corresponding nameMapping element matches the field name in the bean", fieldName, clazz.getName())); } return getter; }
ReflectionUtils { public static Method findGetter(final Object object, final String fieldName) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } final Class<?> clazz = object.getClass(); final String standardGetterName = getMethodNameForField(GET_PREFIX, fieldName); Method getter = findGetterWithCompatibleReturnType(standardGetterName, clazz, false); if( getter == null ) { final String booleanGetterName = getMethodNameForField(IS_PREFIX, fieldName); getter = findGetterWithCompatibleReturnType(booleanGetterName, clazz, true); } if( getter == null ) { throw new SuperCsvReflectionException( String .format( "unable to find getter for field %s in class %s - check that the corresponding nameMapping element matches the field name in the bean", fieldName, clazz.getName())); } return getter; } }
ReflectionUtils { public static Method findGetter(final Object object, final String fieldName) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } final Class<?> clazz = object.getClass(); final String standardGetterName = getMethodNameForField(GET_PREFIX, fieldName); Method getter = findGetterWithCompatibleReturnType(standardGetterName, clazz, false); if( getter == null ) { final String booleanGetterName = getMethodNameForField(IS_PREFIX, fieldName); getter = findGetterWithCompatibleReturnType(booleanGetterName, clazz, true); } if( getter == null ) { throw new SuperCsvReflectionException( String .format( "unable to find getter for field %s in class %s - check that the corresponding nameMapping element matches the field name in the bean", fieldName, clazz.getName())); } return getter; } private  ReflectionUtils(); }
ReflectionUtils { public static Method findGetter(final Object object, final String fieldName) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } final Class<?> clazz = object.getClass(); final String standardGetterName = getMethodNameForField(GET_PREFIX, fieldName); Method getter = findGetterWithCompatibleReturnType(standardGetterName, clazz, false); if( getter == null ) { final String booleanGetterName = getMethodNameForField(IS_PREFIX, fieldName); getter = findGetterWithCompatibleReturnType(booleanGetterName, clazz, true); } if( getter == null ) { throw new SuperCsvReflectionException( String .format( "unable to find getter for field %s in class %s - check that the corresponding nameMapping element matches the field name in the bean", fieldName, clazz.getName())); } return getter; } private  ReflectionUtils(); static Method findGetter(final Object object, final String fieldName); static Method findSetter(final Object object, final String fieldName, final Class<?> argumentType); }
ReflectionUtils { public static Method findGetter(final Object object, final String fieldName) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } final Class<?> clazz = object.getClass(); final String standardGetterName = getMethodNameForField(GET_PREFIX, fieldName); Method getter = findGetterWithCompatibleReturnType(standardGetterName, clazz, false); if( getter == null ) { final String booleanGetterName = getMethodNameForField(IS_PREFIX, fieldName); getter = findGetterWithCompatibleReturnType(booleanGetterName, clazz, true); } if( getter == null ) { throw new SuperCsvReflectionException( String .format( "unable to find getter for field %s in class %s - check that the corresponding nameMapping element matches the field name in the bean", fieldName, clazz.getName())); } return getter; } private  ReflectionUtils(); static Method findGetter(final Object object, final String fieldName); static Method findSetter(final Object object, final String fieldName, final Class<?> argumentType); static final String SET_PREFIX; static final String GET_PREFIX; static final String IS_PREFIX; }