Skip to content
This repository was 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

@hkothari

Description

@hkothari

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);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions