StatefulBeanToCsv wraps null values in quotes
Brought to you by:
aruckerjones,
sconway
When calling StatefulBeanToCsv.write(), empty strings are written as ,"", rather than ,,
. Looking at a post by Conway in 2017, this shouldn't be the case:
I don't see anything in the documentation that shows how to produce empty/blanks for null values (e.g. ,,) other than setting ".withApplyQuotesToAll()" with false, which would not be a desireable solution.
Hello Bret - This is Conway <bg>. I think you misread the post because by default empty strings are surrounded by double quotes and null values are not. That is how opencsv differentiates between the two values when reading them afterwards. </bg>
In 4.2 you can create a CSVParserBuilder and control what is considered a null field but your would still need the applyQuotesToAll as false as seen in this test from CSVParserWriterSpec.
~~~
@Unroll
def 'withFieldAsNull writes correctly with the CSVParserWriter #nullFieldIndicator'(CSVReaderNullFieldIndicator nullFieldIndicator, String expectedResult) {
given:
String[] values = ["First", null, "", "Last"]
~~~
Closed for lack of a response.