in src/main/java/com/univocity/parsers/annotations/helpers/AnnotationHelper.java [453:491]
private static void invokeSetter(Object formatter, PropertyWrapper property, final String value) {
Method writeMethod = property.getWriteMethod();
if (writeMethod == null) {
DataProcessingException exception = new DataProcessingException("Cannot set property '" + property.getName() + "' of formatter '" + formatter.getClass() + "' to '{value}'. No setter defined");
exception.setValue(value);
throw exception;
}
Class<?> parameterType = writeMethod.getParameterTypes()[0];
Object parameterValue = null;
if (parameterType == String.class) {
parameterValue = value;
} else if (parameterType == Integer.class || parameterType == int.class) {
parameterValue = Integer.parseInt(value);
} else if (parameterType == Character.class || parameterType == char.class) {
parameterValue = value.charAt(0);
} else if (parameterType == Currency.class) {
parameterValue = Currency.getInstance(value);
} else if (parameterType == Boolean.class || parameterType == boolean.class) {
parameterValue = Boolean.valueOf(value);
} else if (parameterType == TimeZone.class) {
parameterValue = TimeZone.getTimeZone(value);
} else if (parameterType == DateFormatSymbols.class) {
parameterValue = DateFormatSymbols.getInstance(new Locale(value));
}
if (parameterValue == null) {
DataProcessingException exception = new DataProcessingException("Cannot set property '" + property.getName() + "' of formatter '" + formatter.getClass() + ". Cannot convert '{value}' to instance of " + parameterType);
exception.setValue(value);
throw exception;
}
try {
writeMethod.invoke(formatter, parameterValue);
} catch (Throwable e) {
DataProcessingException exception = new DataProcessingException("Error setting property '" + property.getName() + "' of formatter '" + formatter.getClass() + ", with '{parameterValue}' (converted from '{value}')", e);
exception.setValue("parameterValue", parameterValue);
exception.setValue(value);
throw exception;
}
}