I've upgraded our OpenCSV version from 1.8 to 4.1.
With version 4.1 OpenCSV fails to parse the following lines:
MODIFY ACEUD-2052 TVG00420 8806088726823 0 645.88 TV Gerät LED-LCD 140 cm (55) Samsung UE55MU6402 (1500Hz,SmartTV,4K) USB-Recording 645.88 EUR "{""rawArticleType"":""TV Geräte/139 cm (55\"")/LCD""}"
MODIFY ACEUD-2052 TVG00515 8806088692401 0 2397.73 TV Gerät LED-LCD 190 cm (75) Samsung UE75MU8002 (2600Hz,SmartTV,4K) USB-Recording 2397.73 EUR "{""rawArticleType"":""TV Geräte/190 cm (75\"")/LCD""}"
MODIFY ACEUD-2052 VG001183 4719331339302 0 103.30 VGA 2GB GIGABYTE GeForce GTX1050 D5 2G (HDMI,DP,DVI) 103.30 EUR "{""rawArticleType"":""Grafikkarten/PCI-Express/NVIDIA""}"
I believe the problem is on the (75\"") part of the json.
OpenCSV fails with the following exception:
java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: Unterminated quoted field at end of CSV line. Beginning of lost text: [{"rawArticleType":"TV Geräte/190 cm (75"")/LCD"} MODIFY ACEUD-2052 VG001183 4719331339302 0 103.3...]
This same string is processed successfully by version 1.8
Here is the code to build the parser and reader
csvParser = new CSVParserBuilder()
.withSeparator((char) (int) separatorChar)
.withQuoteChar((char) (int) quoteChar)
.build();
csvReader = new CSVReaderBuilder(inputStreamReader)
.withCSVParser(csvParser)
.build();
Where separatorChar
is a TAB (int value 9) and quoteChar
is '"', quote char, (int value 34)
The code above runs fine with version 1.8 but fails with version 4.1
On version 4.1 I see there is a CSVParserBuilder()#withIgnoreQuotations(boolean value)
OpenCSV4.1-Javadoc link
If I set it to true then the lines are processed without exceptions but then the output is {"rawArticleType":"Displays/60 - 61 cm (24""")/WUXGA (1920x1200)"}
which is not valid json and will be skipped by the json parser that is downstream which makes this not acceptable solution.
I also tried to set the escape char to "
(single quote) but then OpenCSV raises an exception complaining
java.lang.UnsupportedOperationException: The separator, quote, and escape characters must be different!
Again, my question is what am I doing wrong to be able to parse those strings and output valid json?
EDIT:
I'm reading the CSV file by using csvReader.readNext()