-
Notifications
You must be signed in to change notification settings - Fork 199
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
Adding uniVocity support #258
Conversation
Hello Anthony, Fantastic! That's great 👍 This is what we call a very high quality pull request 😄 Keep the good work up on univocity! Best regards |
Hi Anthony, The build is failing on windows (I have to add a CI for windows in addition to mac/linux, travis-ci does not support windows yet..). The following tests are failing:
I have already fixed 1, 2 and 3 by replacing "\n" with Utils.LINE_SEPARATOR. I'll push the fix asap. For the 4th test, it seems like the CsvParser converts "\r\n" to "\n". Here is a failing test that isolates the problem: @Test
public void testUnivocityCsvCarriageReturnLineFeed() throws Exception {
BeanListProcessor<TestBean> beanListProcessor = new BeanListProcessor<>(TestBean.class);
CsvParserSettings csvParserSettings = new CsvParserSettings();
csvParserSettings.getFormat().setQuote('\'');
csvParserSettings.setProcessor(beanListProcessor);
CsvParser parser = new CsvParser(csvParserSettings);
String payload = "'foo" + LINE_SEPARATOR + "','bar" + LINE_SEPARATOR + "'";
parser.parse(new StringReader(payload));
TestBean result = beanListProcessor.getBeans().get(0);
assertThat(result).isNotNull();
assertThat(result.getFirstName()).isEqualTo("foo" + LINE_SEPARATOR);
assertThat(result.getLastName()).isEqualTo("bar" + LINE_SEPARATOR);
} I tried to set some options: csvParserSettings.setDelimiterDetectionEnabled(true);
csvParserSettings.setQuoteDetectionEnabled(true);
csvParserSettings.setLineSeparatorDetectionEnabled(true); but it still failing. The Kr |
Hey Mahmoud, I'll investigate this tonight. As a quick guess explicitly setting the line separator may help. e.g. csvParserSettings.getFormat().setLineSeparator(LINE_SEPARATOR); Also maybe ending the payload string with a line separator as well. e.g: String payload = "'foo" + LINE_SEPARATOR + "','bar" + LINE_SEPARATOR + "'" + LINE_SEPARATOR;` |
Oh thanks! I tried both of these changes and it is still failing. I'll continue investigating on my side. Let me know if you find something interesting. Kr |
I have updated tests to ignore os specific line endings, but still, I'm curious to know why this is failing on windows.. |
Hey mate, Found the problem. You need to add the following code: csvParserSettings.setNormalizeLineEndingsWithinQuotes(false); Basically, uniVocity will replace a detected line separator that is within quotes with whatever the normalized line separator (default is Hope this solves everything. If you have any more questions, feel free to ask! Altough you owe me for making be boot into Windows 😉 |
I came across this setting and set it to true (not false).. Now it is more clear to me. Thank you for your time! |
This pull request adds a uniVocity extension so that CSV, TSV and Fixed Width Formats can be mapped and marshalled.