Menu

#171 Default StringProcessor

open
None
5
2025-04-23
2025-04-21
No

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);
}

Discussion

  • Scott Conway

    Scott Conway - 2025-04-23
    • assigned_to: Scott Conway
     
  • Scott Conway

    Scott Conway - 2025-04-23

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.