diff --git a/src/main/java/org/csveed/row/RowWriterImpl.java b/src/main/java/org/csveed/row/RowWriterImpl.java index bb6c6e79..a8400b0a 100644 --- a/src/main/java/org/csveed/row/RowWriterImpl.java +++ b/src/main/java/org/csveed/row/RowWriterImpl.java @@ -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() } ); diff --git a/src/test/java/org/csveed/api/CsvClientTest.java b/src/test/java/org/csveed/api/CsvClientTest.java index 0f1b24d6..b8b27cff 100644 --- a/src/test/java/org/csveed/api/CsvClientTest.java +++ b/src/test/java/org/csveed/api/CsvClientTest.java @@ -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 client = new CsvClientImpl( + 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);