-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Allow skipping ending line break (CsvGenerator.Feature.WRITE_LINEFEED_AFTER_LAST_ROW
)
#45
Comments
Ok, sounds reasonable from usage perspective. Not sure how easy it'd be to do, wrt. when determination is made regarding adding a linefeed: if it's at the time of starting a new line, this should be quite easy. There is also the question of whether this belongs in schema, or as a |
should the |
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 Label is purely aspirational, i.e. at the time of update possible target. Updated to 2.10 as this can not be added in 2.9 any more; 2.10 is still possible. Milestone will indicate actual inclusion if and when that happens. |
@tyler2cr the "<>" is just how JUnit describes an empty string in the |
@cowtowncoder Sounds good - thanks for the quick response! |
@rage-shadowman 🤦♂ thank you!! After this realization, I used |
Any progress on this? |
@alturkovic I don't think so. I definitely haven't had time to try to implement this. But if (or anyone else) has time and interest, would be happy to help get a contributed PR merged. EDIT: I forgot there's a PR -- #46 - that proposes a way to do it. Unfortunately I don't think it quite works reliably in that there might be a case where multi-character linefeed ( On changes to #46: I think that this should be enabled using Aside from that I think ensuring "undo last linefeed" works reliably is probably doable. |
Hmmh. Actually, code for I'll add a note on #46 wrt other change. |
CsvGenerator.Feature.WRITE_LINEFEED_AFTER_LAST_ROW
)
CsvGenerator.Feature.WRITE_LINEFEED_AFTER_LAST_ROW
)CsvGenerator.Feature.WRITE_LINEFEED_AFTER_LAST_ROW
)
Implemented for 2.17.0 (see #453) |
In RFC-4180 it is said that CSV implementations may choose to include a line break at the end of the file or not.
It could be nice to add an option to choose. For instance something like this :
The text was updated successfully, but these errors were encountered: