Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Change Default Outputting Behavior to Include Final Comma Regardless of Value #45

Closed
hkothari opened this issue May 26, 2014 · 1 comment
Milestone

Comments

@hkothari
Copy link

Currently the default behavior is to ignore the final comma when writing a row which has a null final value, whether or not this is a valid CSV, by default we should be including the final comma. See the following unit test, adapted from @Magrath's code from #33:

    @Test
    public void testWrite_NullThirdColumn() throws JsonProcessingException {
        final CsvSchema.Builder csvSchemaBuilder = new CsvSchema.Builder();
        csvSchemaBuilder.addColumn("timestamp", CsvSchema.ColumnType.STRING);
        csvSchemaBuilder.addColumn("value", CsvSchema.ColumnType.NUMBER);
        csvSchemaBuilder.addColumn("id", CsvSchema.ColumnType.STRING);
        final CsvSchema schema = csvSchemaBuilder.build();
        final ObjectWriter writer = new CsvMapper().writer().withSchema(schema);

        final String string = writer.writeValueAsString(
                ImmutableMap.of("timestamp", "2014-03-10T23:32:47+00:00",
                        "value", 42));

        assertEquals("\"2014-03-10T23:32:47+00:00\",42,\n", string);
    }
cowtowncoder added a commit that referenced this issue May 26, 2014
@cowtowncoder
Copy link
Member

Changed default, but might as well also add the feature for alternate behavior next.

@cowtowncoder cowtowncoder added this to the 2.4.0 milestone May 26, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants