Parsing double quote from csv using jackson-dataformat-csv

prettyvoid :

I have a csv that contains the following

EANHotelID|SequenceNumber|Name|Address1|Address2|City|StateProvince|PostalCode|Country|Latitude|Longitude|AirportCode|PropertyCategory|PropertyCurrency|StarRating|Confidence|SupplierType|Location|ChainCodeID|RegionID|HighRate|LowRate|CheckInTime|CheckOutTime
541454|99999999|Hotel Maan Residency|"B" Wing, Gopal Palace, opp. ocean park|Naherunagar-Satellite Road|Ahmedabad||380 015|IN|23.02266|72.53842|AMD|1|INR|3.0||ESR|Near Kankaria Lake|||0|0|10:00 AM|10:00 AM

Now I'm trying to read each row in this csv as an object using the following code

    CsvMapper mapper = new CsvMapper();
    mapper.findAndRegisterModules();

    File csvFile = new File("D:\\ActivePropertyList.txt.bak2");

    CsvSchema schema = CsvSchema.emptySchema().withHeader().withColumnSeparator('|').withNullValue("");
    MappingIterator<Map<String,String>> it = mapper.readerFor(Map.class).with(schema)
                .readValues(csvFile);

    while (it.hasNextValue()) {
        Map<String,String> value = it.nextValue();
    }

But it's failing because of the "B" that exists in the csv. I get the following error:

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('W' (code 87)): Expected separator ('"' (code 34)) or end-of-line at [Source: (com.fasterxml.jackson.dataformat.csv.impl.UTF8Reader); line: 2, column: 43]

How can I parse the double quotes in the csv correctly? I tried playing around with schema.withEscapeChar() schema.withQuoteChar() but I couldn't get it to work.

prettyvoid :

Use withoutQuoteChar() on the schema to handle double quotations in the csv content, i.e.

CsvSchema.emptySchema().withHeader().withColumnSeparator('|').withNullValue("").withoutQuoteChar();

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=469665&siteId=1