Reputation: 2534
I have the following CSV format:
id,name,description,age
23,Anna,"Self-made
Chef
Shoemaker",23
The double-quotes are only present if the attribute is multi-line. While I am already been able to read the normal CSV correctly:
@Bean
public CsvMapper csvMapper() {
CsvMapper csvMapper = new CsvMapper();
csvMapper.registerModule(new JavaTimeModule());
csvMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
return csvMapper;
}
I tried adding a new feature:
csvMapper.configure(Feature.FAIL_ON_MISSING_COLUMNS, true);
But it makes the library skip failed rows. How do I parse the given format and get the whole Self-made\n Chef\n Shoemaker
into the description attribute?
Upvotes: 2
Views: 887
Reputation: 718986
According to my reading of the code in the CSVDecoder
class (link), the Jackson CSV parser in version 2.14 will correctly parse double-quoted strings that have embedded line-breaks. Look for the _nextQuotedString
method. No attribute needs to be set to enable this. It happens unconditionally.
Indeed, it looks like the relevant lines of the code have not changed in at least 5 years.
So ... if the CSV parser is not working for you (without that Feature
), my diagnosis is:
If this doesn't solve your problem, please add a minimal reproducible example to the Question, and tell us the version(s) of the Jackson dependencies you are using.
Upvotes: 0