Search code examples
opencsv

CsvToBean treat string value as null


Is there a way for CsvToBean to treat a specific string or character as null when it maps into a Bean class?

For example I have a CSV that has a quoted value of "-". I know that when creating a CsvToBean you can specify

.withFieldAsNull(CSVReaderNullFieldIndicator)

which handles cases when a value is not present in CSV data. Just can't find a way to treat a character value as null.


Solution

  • No OpenCSV does not do data translation like that. You will have to change your the setters in your bean to translate the value as you are setting it.