Default StringProcessor
Brought to you by:
aruckerjones,
sconway
When using opencsv, I often find my self adding ConvertEmptyOrBlankStringsToNull to all String fields.
It would be great to have a way to add the default StringProcessor in the MappingStategy and use it when none is provided.
Workaround:
CustomMappingStategy with:
@Override
protected void setFieldValue(Map<Class<?>, Object> beanTree, String value, int column) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException, CsvConstraintViolationException, CsvValidationException {
if (value == null || value.trim().isBlank() || value.equalsIgnoreCase("null")) {
super.setFieldValue(beanTree, null, column);
}
super.setFieldValue(beanTree, value, column);
}
Hello Youssef. I might try and play with this to see how this plays out. But my first thought is to reject this because even though it is the most common use for you may be distruptive for users who expect the current default behavior.
Feel free to extend an existing strategy and override the setFieldValue. If there are any methods you need me to make protected let me know.