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 e86deba..30e33a3 100644 --- a/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvGenerator.java +++ b/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvGenerator.java @@ -428,6 +428,12 @@ public void close() throws IOException // Let's mark row as closed, if we had any... finishRow(); + + // Write the header if necessary, occurs when no rows written + if (_handleFirstLine) { + _handleFirstLine(); + } + _writer.close(_ioContext.isResourceManaged() || isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET)); }