in src/main/java/com/univocity/parsers/annotations/helpers/FieldMapping.java [328:393]
public void write(Object instance, Object value) {
setAccessible();
try {
if (primitive) {
if (value == null) {
if (applyDefault == null) {
Object currentValue = read(instance, true);
applyDefault = defaultPrimitiveValue.equals(currentValue);
}
if (applyDefault == Boolean.TRUE) {
value = defaultPrimitiveValue;
} else {
return;
}
} else if (defaultPrimitiveValue.getClass() != value.getClass() && value instanceof Number) {
Number number = ((Number) value);
if (fieldType == int.class) {
value = number.intValue();
} else if (fieldType == long.class) {
value = number.longValue();
} else if (fieldType == double.class) {
value = number.doubleValue();
} else if (fieldType == float.class) {
value = number.floatValue();
} else if (fieldType == byte.class) {
value = number.byteValue();
} else if (fieldType == short.class) {
value = number.shortValue();
}
}
}
if (writeMethod != null) {
writeMethod.invoke(instance, value);
} else {
((Field) target).set(instance, value);
}
} catch (Throwable e) {
String valueTypeName = value == null ? null : value.getClass().getName();
String msg;
String details = null;
if (valueTypeName != null) {
msg = "Unable to set value '{value}' of type '" + valueTypeName + "' to field " + toString();
} else {
msg = "Unable to set value 'null' to field " + toString();
}
if (e instanceof InvocationTargetException) {
e = e.getCause();
details = msg;
}
if (e instanceof DataProcessingException) {
DataProcessingException ex = (DataProcessingException) e;
ex.markAsNonFatal();
ex.setValue(value);
ex.setDetails(details);
throw (DataProcessingException) e;
}
DataProcessingException ex = new DataProcessingException(msg, e);
ex.markAsNonFatal();
ex.setValue(value);
throw ex;
}
}