Skip to content

Commit

Permalink
Issue 42BV#53 do not attempt to write null fields - will make col1;;col3
Browse files Browse the repository at this point in the history
  • Loading branch information
mparaz committed Dec 11, 2014
1 parent 34fc884 commit 3a771cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/csveed/row/RowWriterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ private void writeSeparator() throws IOException {
}

private void writeCell(String cell) throws IOException {
if (cell == null) {
return;
}

writer.write(rowInstructions.getQuote());
String searchString = Character.toString(rowInstructions.getQuote());
String replaceString = new String(new char[] { rowInstructions.getEscape(), rowInstructions.getQuote() } );
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/org/csveed/api/CsvClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ writer, new BeanInstructionsImpl(BeanWithMultipleStrings.class)
writer.getBuffer().toString());
}

@Test
public void writeBeanBasedOnInstructionsWithNull() throws IOException {
StringWriter writer = new StringWriter();
BeanWithMultipleStrings bean = createBean(null, "row 1, cell 2", "row 1, cell 1");
CsvClient<BeanWithMultipleStrings> client = new CsvClientImpl<BeanWithMultipleStrings>(
writer, new BeanInstructionsImpl(BeanWithMultipleStrings.class)
.mapColumnNameToProperty("alpha", "alpha")
.mapColumnNameToProperty("beta", "beta")
.ignoreProperty("gamma")
);
client.writeBean(bean);
writer.close();
assertEquals(
"\"beta\";\"alpha\"\r\n"+
"\"row 1, cell 2\";\r\n",
writer.getBuffer().toString());
}



private BeanWithMultipleStrings createBean(String alpha, String beta, String gamma) {
BeanWithMultipleStrings bean = new BeanWithMultipleStrings();
bean.setAlpha(alpha);
Expand Down

0 comments on commit 3a771cf

Please sign in to comment.