I'm trying to deserialize a csv(tsv) file into an immutable POJO.
Jackson is assigning values to the wrong fields (it's ignoring the annotated column header name) The class fields are written in the same order as found in the file.
Do I really have to create a custom CSV schema for this? What's the point of "withHeader()" anyway, just ignore the first line??
I tried editing the csv(tsv) file's headers changing the name to something not annotated, but no error occurs.
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public Person(@JsonProperty("name") String name,
@JsonProperty("address") String address,
@JsonProperty("phone") String phone) {
this.name = name;
...
}
CsvMapper mapper = new CsvMapper();
CsvSchema schema = mapper.schemaFor(Person.class).withColumnSeparator('\t').withHeader();
MappingIterator<Person> it = mapper.readerFor(Person.class).with(schema).readValues(file);