-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
Can't change set of accepted linefeed characters for parser #35
Comments
Almost but not quite: line separator is only configurable for writing (generation); for reading (parsing) three standard line-feeds ("\n", "\r", "\r\n") are accepted. |
This requested feature may resolve an unexpected scenario: These tests fail with I've been unable to determine where the import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class newlinetest {
@JsonPropertyOrder({"column1", "column2"})
static
class Pojo {
private String column1;
private String column2;
public String getColumn1() {
return column1;
}
public void setColumn1(String column1) {
this.column1 = column1;
}
public String getColumn2() {
return column2;
}
public void setColumn2(String column2) {
this.column2 = column2;
}
}
@Test
public void two_rows() throws IOException {
// setup
String csv = "value|\nvalue|\n";
CsvMapper csvMapper = new CsvMapper();
CsvSchema csvSchema = csvMapper.schemaFor(Pojo.class).withColumnSeparator('|');
// execute
MappingIterator<Pojo> mappingIterator = csvMapper.readerFor(Pojo.class).with(csvSchema).readValues(csv);
// test
assertTrue(mappingIterator.hasNext());
Pojo row1 = mappingIterator.next();
assertNotNull(row1);
assertEquals("value", row1.column1);
assertNull(row1.column2);
}
@Test
public void one_row() throws IOException {
// setup
String csv = "value|\n";
CsvMapper csvMapper = new CsvMapper();
CsvSchema csvSchema = csvMapper.schemaFor(Pojo.class).withColumnSeparator('|');
// execute
Pojo pojo = csvMapper.readerFor(Pojo.class).with(csvSchema).readValue(csv);
// test
assertNotNull(pojo);
assertEquals("value", pojo.column1);
assertNull(pojo.column2);
}
} |
@tyler2cr the "<>" comes from JUnit. It's just telling you that it expected |
@rage-shadowman 🤦♂ thank you!! After this realization, I used |
Ok, I think I can close this issue since I am not sure what work would be expected here: it seems like question was about alternate linefeeds like |
@cowtowncoder could the reader be enhanced to use customized line feed endings? (the writer already can, per your comment) If so, this ticket could be reopened since it's talking about the parser |
@tyler2cr In theory, yes, in practice, that is not necessarily an easy change. But what I would need is a real use-case for why such a feature is needed: I have learned not to work on hypothetical use cases. So: given that all standard (\n, \r, \r\n) linefeeds work, what is the missing use case (why and what). Especially since users may implement So: if someone has specific use case, please add details here and this issue can be re-opened and perhaps someone could try to implement it. |
In documentation it is written that we can change Linefeed character. But when I try with different Linefeed character, it is not parsing correctly. Below is test case
But same test case is working when I change the Linefeed char to "\n" in my data. e.g.,
It means that currently Jackson Csv parser only supports "\n" as a line delimiter. right?
The text was updated successfully, but these errors were encountered: