When using opencsv with annotation and StatefulBeanToCsv, headers are not written when bean list is empty.
I would assume this test successful but it's not.
private class bean1 {
@CsvBindByName(column = "column1")
private String col1;
public String getCol1() {
return col1;
}
public void setCol1(String col1) {
this.col1 = col1;
}
}
@Test
public void testOpenCsvEmptyBeanList() throws CsvException {
StringWriter sw = new StringWriter();
StatefulBeanToCsv<bean1> sbc = new StatefulBeanToCsvBuilder<bean1>(sw)
.withLineEnd(CSVWriter.DEFAULT_LINE_END)
.build();
// empty bean list
sbc.write(new ArrayList<>());
assertEquals("column1" + CSVWriter.DEFAULT_LINE_END, sw.toString());
}
Any idea to make this test works ?
question from:
https://stackoverflow.com/questions/65882442/opencsv-doesnt-write-headers-in-case-of-empty-bean-list 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…