diff --git a/release-notes/VERSION b/release-notes/VERSION index 7e9b285..3d6426a 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -1,6 +1,8 @@ Project: jackson-dataformat-csv Version: 2.3.3 (xx-xxx-2014) +#33: CSV is written without column separators if first column is null + (reported by Paul M) - Fix a minor problem with `CsvSchema` defaults: was setting default escape char to be same as default quote (i.e. double-quote) diff --git a/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvGenerator.java b/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvGenerator.java index 1674307..461e569 100644 --- a/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvGenerator.java +++ b/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvGenerator.java @@ -139,8 +139,7 @@ public Version version() { * (should we throw an exception instead?) */ @Override - public CsvGenerator useDefaultPrettyPrinter() - { + public CsvGenerator useDefaultPrettyPrinter() { return this; } @@ -597,8 +596,7 @@ protected final void _verifyValueWrite(String typeMsg) } @Override - protected void _releaseBuffers() - { + protected void _releaseBuffers() { _writer._releaseBuffers(); } diff --git a/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvWriter.java b/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvWriter.java index 71647d7..f025e8f 100644 --- a/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvWriter.java +++ b/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvWriter.java @@ -273,9 +273,10 @@ public void endRow() throws IOException _lastBuffered = -1; for (int i = _nextColumnToWrite; i <= last; ++i) { BufferedValue value = _buffered[i]; - if (value == null) { // missing value still needs separator + if (i > _nextColumnToWrite) { appendColumnSeparator(); - } else { + } + if (value != null) { _buffered[i] = null; value.write(this); } @@ -304,7 +305,7 @@ protected void appendValue(String value) throws IOException _flushBuffer(); } if (_nextColumnToWrite > 0) { - _outputBuffer[_outputTail++] = _cfgColumnSeparator; + appendColumnSeparator(); } /* First: determine if we need quotes; simple heuristics; * only check for short Strings, stop if something found @@ -382,14 +383,11 @@ protected void appendValue(boolean value) throws IOException _outputTail += len; } - protected void appendColumnSeparator() throws IOException - { - if (_nextColumnToWrite > 0) { - if (_outputTail >= _outputTail) { - _flushBuffer(); - } - _outputBuffer[_outputTail++] = _cfgColumnSeparator; + protected void appendColumnSeparator() throws IOException { + if (_outputTail >= _outputTail) { + _flushBuffer(); } + _outputBuffer[_outputTail++] = _cfgColumnSeparator; } /*