diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/JacksonCSVRecordReader.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/JacksonCSVRecordReader.java index 91cca81097..a25df65812 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/JacksonCSVRecordReader.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/JacksonCSVRecordReader.java @@ -103,7 +103,7 @@ public class JacksonCSVRecordReader implements RecordReader { CsvSchema csvSchema = csvSchemaBuilder.build(); // Add remaining config options to the mapper - List features = new ArrayList<>(3); + List features = new ArrayList<>(); features.add(CsvParser.Feature.INSERT_NULLS_FOR_MISSING_COLUMNS); if (csvFormat.getIgnoreEmptyLines()) { features.add(CsvParser.Feature.SKIP_EMPTY_LINES); @@ -114,7 +114,7 @@ public class JacksonCSVRecordReader implements RecordReader { ObjectReader objReader = mapper.readerFor(String[].class) .with(csvSchema) - .withFeatures(features.toArray(new CsvParser.Feature[3])); + .withFeatures(features.toArray(new CsvParser.Feature[features.size()])); recordStream = objReader.readValues(reader); } diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/csv/TestJacksonCSVRecordReader.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/csv/TestJacksonCSVRecordReader.java index 9e085949bf..66486eef1a 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/csv/TestJacksonCSVRecordReader.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/csv/TestJacksonCSVRecordReader.java @@ -123,6 +123,29 @@ public class TestJacksonCSVRecordReader { } } + @Test + public void testExcelFormat() throws IOException, MalformedRecordException { + final List fields = new ArrayList(); + fields.add(new RecordField("fieldA", RecordFieldType.STRING.getDataType())); + fields.add(new RecordField("fieldB", RecordFieldType.STRING.getDataType())); + final RecordSchema schema = new SimpleRecordSchema(fields); + + final String headerLine = "fieldA,fieldB"; + final String inputRecord = "valueA,valueB"; + final String csvData = headerLine + "\n" + inputRecord; + final byte[] inputData = csvData.getBytes(); + + try (final InputStream bais = new ByteArrayInputStream(inputData); + final JacksonCSVRecordReader reader = createReader(bais, schema, CSVFormat.EXCEL)) { + + final Object[] record = reader.nextRecord().getValues(); + final Object[] expectedValues = new Object[] {"valueA", "valueB"}; + Assert.assertArrayEquals(expectedValues, record); + + assertNull(reader.nextRecord()); + } + } + @Test public void testMultipleRecords() throws IOException, MalformedRecordException { final List fields = getDefaultFields();