Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CsvGenerator.Feature to fail if linefeeds included in quoted content #11

Open
cowtowncoder opened this issue Mar 20, 2017 · 1 comment
Labels

Comments

@cowtowncoder
Copy link
Member

(from FasterXML/jackson-dataformat-csv#118 by @balbusm)

CsvSchema schema = CsvSchema.emptySchema().withHeader();
FileReader fileReader = new FileReader(file);
MappingIterator<Map<String,String>> it = mapper.readerFor(Map.class)
  .with(schema)
  .readValues(fileReader);
while (it.hasNext()) {
  try {
    Map<String,String> rowAsMap = it.next();
    System.out.println(rowAsMap);
  } catch (Exception e) {
    System.out.println(e);
  }
}

Example input:

1,Head2,Head3,Head4,"Head5
2,Head2,Head3,Head4,Head5
3,Head2,Head3,Head4,Head5
@cowtowncoder
Copy link
Member Author

cowtowncoder commented Mar 20, 2017

Hmmh. Unfortunately I am not sure this is possible: since linefeeds are acceptable within quoted content, the last value would enclose lines 2 and 3. So although recovery should be able to recover from missing end quote, that would not help a lot given that the one logical line that exists would be skipped.

One possibility here would be addition of the CSV read feature, or possible a CsvSchema property, which would enable/disable ability to contain linefeeds within quoted content.

Another question would be that of what to do with linefeeds: convert to spaces, drop, or throw exception. I assume first (spaces) or last (exception) are most likely actions.

@cowtowncoder cowtowncoder changed the title (csv) Add CsvGenerator.Feature to fail if linefeeds included in quoted content Add CsvGenerator.Feature to fail if linefeeds included in quoted content Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant