@Test public void testAutoboxing() throws Exception { findSetter(bean, "primitiveBoolean", Boolean.class).invoke(bean, Boolean.TRUE); assertEquals(true, bean.isPrimitiveBoolean()); findSetter(bean, "primitiveInt", Integer.class).invoke(bean, Integer.valueOf(1)); assertEquals(1, bean.getPrimitiveInt()); findSetter(bean, "primitiveShort", Short.class).invoke(bean, Short.valueOf("2")); assertEquals(Short.parseShort("2"), bean.getPrimitiveShort()); findSetter(bean, "primitiveLong", Long.class).invoke(bean, Long.valueOf("3")); assertEquals(Long.parseLong("3"), bean.getPrimitiveLong()); findSetter(bean, "primitiveDouble", Double.class).invoke(bean, Double.valueOf("4.0")); assertEquals(Double.parseDouble("4.0"), bean.getPrimitiveDouble(), DOUBLE_ASSERT_DELTA); findSetter(bean, "primitiveFloat", Float.class).invoke(bean, Float.valueOf("5.0")); assertEquals(Float.parseFloat("5.0"), bean.getPrimitiveFloat(), DOUBLE_ASSERT_DELTA); findSetter(bean, "primitiveChar", Character.class).invoke(bean, Character.valueOf('a')); assertEquals('a', bean.getPrimitiveChar()); findSetter(bean, "primitiveByte", Byte.class).invoke(bean, Byte.valueOf("123")); assertEquals(Byte.parseByte("123"), bean.getPrimitiveByte()); findSetter(bean, "booleanWrapper", boolean.class).invoke(bean, true); assertEquals(Boolean.TRUE, bean.getBooleanWrapper()); findSetter(bean, "integerWrapper", int.class).invoke(bean, 1); assertEquals(Integer.valueOf(1), bean.getIntegerWrapper()); findSetter(bean, "shortWrapper", short.class).invoke(bean, Short.parseShort("2")); assertEquals(Short.valueOf("2"), bean.getShortWrapper()); findSetter(bean, "longWrapper", long.class).invoke(bean, Long.parseLong("3")); assertEquals(Long.valueOf("3"), bean.getLongWrapper()); findSetter(bean, "doubleWrapper", double.class).invoke(bean, Double.parseDouble("4.0")); assertEquals(Double.valueOf("4.0"), bean.getDoubleWrapper()); findSetter(bean, "floatWrapper", float.class).invoke(bean, Float.parseFloat("5.0")); assertEquals(Float.valueOf("5.0"), bean.getFloatWrapper()); findSetter(bean, "charWrapper", char.class).invoke(bean, 'a'); assertEquals(Character.valueOf('a'), bean.getCharWrapper()); findSetter(bean, "byteWrapper", byte.class).invoke(bean, Byte.parseByte("123")); assertEquals(Byte.valueOf("123"), bean.getByteWrapper()); }
public static Method findSetter(final Object object, final String fieldName, final Class<?> argumentType) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } else if( argumentType == null ) { throw new NullPointerException("argumentType should not be null"); } final String setterName = getMethodNameForField(SET_PREFIX, fieldName); final Class<?> clazz = object.getClass(); Method setter = findSetterWithCompatibleParamType(clazz, setterName, argumentType); if( setter == null && AUTOBOXING_CONVERTER.containsKey(argumentType) ) { setter = findSetterWithCompatibleParamType(clazz, setterName, AUTOBOXING_CONVERTER.get(argumentType)); } if( setter == null ) { throw new SuperCsvReflectionException( String .format( "unable to find method %s(%s) in class %s - check that the corresponding nameMapping element matches the field name in the bean, " + "and the cell processor returns a type compatible with the field", setterName, argumentType.getName(), clazz.getName())); } return setter; }
ReflectionUtils { public static Method findSetter(final Object object, final String fieldName, final Class<?> argumentType) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } else if( argumentType == null ) { throw new NullPointerException("argumentType should not be null"); } final String setterName = getMethodNameForField(SET_PREFIX, fieldName); final Class<?> clazz = object.getClass(); Method setter = findSetterWithCompatibleParamType(clazz, setterName, argumentType); if( setter == null && AUTOBOXING_CONVERTER.containsKey(argumentType) ) { setter = findSetterWithCompatibleParamType(clazz, setterName, AUTOBOXING_CONVERTER.get(argumentType)); } if( setter == null ) { throw new SuperCsvReflectionException( String .format( "unable to find method %s(%s) in class %s - check that the corresponding nameMapping element matches the field name in the bean, " + "and the cell processor returns a type compatible with the field", setterName, argumentType.getName(), clazz.getName())); } return setter; } }
ReflectionUtils { public static Method findSetter(final Object object, final String fieldName, final Class<?> argumentType) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } else if( argumentType == null ) { throw new NullPointerException("argumentType should not be null"); } final String setterName = getMethodNameForField(SET_PREFIX, fieldName); final Class<?> clazz = object.getClass(); Method setter = findSetterWithCompatibleParamType(clazz, setterName, argumentType); if( setter == null && AUTOBOXING_CONVERTER.containsKey(argumentType) ) { setter = findSetterWithCompatibleParamType(clazz, setterName, AUTOBOXING_CONVERTER.get(argumentType)); } if( setter == null ) { throw new SuperCsvReflectionException( String .format( "unable to find method %s(%s) in class %s - check that the corresponding nameMapping element matches the field name in the bean, " + "and the cell processor returns a type compatible with the field", setterName, argumentType.getName(), clazz.getName())); } return setter; } private  ReflectionUtils(); }
ReflectionUtils { public static Method findSetter(final Object object, final String fieldName, final Class<?> argumentType) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } else if( argumentType == null ) { throw new NullPointerException("argumentType should not be null"); } final String setterName = getMethodNameForField(SET_PREFIX, fieldName); final Class<?> clazz = object.getClass(); Method setter = findSetterWithCompatibleParamType(clazz, setterName, argumentType); if( setter == null && AUTOBOXING_CONVERTER.containsKey(argumentType) ) { setter = findSetterWithCompatibleParamType(clazz, setterName, AUTOBOXING_CONVERTER.get(argumentType)); } if( setter == null ) { throw new SuperCsvReflectionException( String .format( "unable to find method %s(%s) in class %s - check that the corresponding nameMapping element matches the field name in the bean, " + "and the cell processor returns a type compatible with the field", setterName, argumentType.getName(), clazz.getName())); } return setter; } 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 findSetter(final Object object, final String fieldName, final Class<?> argumentType) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } else if( argumentType == null ) { throw new NullPointerException("argumentType should not be null"); } final String setterName = getMethodNameForField(SET_PREFIX, fieldName); final Class<?> clazz = object.getClass(); Method setter = findSetterWithCompatibleParamType(clazz, setterName, argumentType); if( setter == null && AUTOBOXING_CONVERTER.containsKey(argumentType) ) { setter = findSetterWithCompatibleParamType(clazz, setterName, AUTOBOXING_CONVERTER.get(argumentType)); } if( setter == null ) { throw new SuperCsvReflectionException( String .format( "unable to find method %s(%s) in class %s - check that the corresponding nameMapping element matches the field name in the bean, " + "and the cell processor returns a type compatible with the field", setterName, argumentType.getName(), clazz.getName())); } return setter; } 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; }