Skip to content

Incorrect location of CSV errors #483

@RafeArnold

Description

@RafeArnold

Currently, when a JsonProcessingException is thrown when parsing CSV with a missing closing quote, the reported location of the column where the error occurred is incorrect. For example,

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvParser;

import java.io.IOException;
import java.util.List;

public class Test {
    public static void main(String[] args) throws IOException {
        try (MappingIterator<List<String>> reader = new CsvMapper()
                .readerForListOf(String.class)
                .with(CsvParser.Feature.WRAP_AS_ARRAY)
                .readValues("name,dob\n\"an invalid string,2020-05-01")) {
            reader.readAll();
        } catch (JsonProcessingException e) {
            System.out.println("line number: " + e.getLocation().getLineNr());
            System.out.println("column number: " + e.getLocation().getColumnNr());
        }
    }
}

will output

line number: 2
column number: 68

The row number is correct, but the column number is not (there aren't even 68 characters in the entire CSV). I would expect the column number to be more like 30.

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.18Fix or feature targeted at 2.18 releasecsv

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions