Skip to content

Empty Lists can only be String-typed in CSV #199

@sonOfRa

Description

@sonOfRa

When mapping POJOs that contain Lists to CSV, Jackson fails with an exception if that list is empty, and the type of the list is not String:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `java.util.ArrayList` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('') at [Source: (com.fasterxml.jackson.dataformat.csv.impl.UTF8Reader); line: 2, column: 1] (through reference chain: de.slevermann.jackson.csv.Model["LONGS"])

I've provided example code with a failing and a succeeding test case over at https://github.com/sonOfRa/jackson-csv-bug.

I'll provide a shortened version here so it's also preserved in an issue. The following CSV:

STRINGS;OTHER_FIELD
;Hello

successfully gets read by Jackson into the following POJO (getters and setters omitted):

public class Model {

    @JsonProperty("STRINGS")
    private List<String> strings;

    @JsonProperty("OTHER_FIELD")
    private String otherField;
}

The list is empty, and the other field contains "Hello".

However, with the following CSV:

LONGS;OTHER_FIELD
;Hello

Jackson produces the above exception, when attempting to read into the following POJO:

public class Model {

    @JsonProperty("LONGS")
    private List<Long> longs;

    @JsonProperty("OTHER_FIELD")
    private String otherField;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions