Skip to content

Allow WebApiContrib.Core.Formatter.Csv to treat empty columns as empty string -OR- null #142

@AnthonyMastrean

Description

@AnthonyMastrean

It seems like the parser is treating empty columns as the empty string, not null. Using the following model and example CSV, this library will produce an empty string for the 2nd Message property. I'd prefer for these to be treated as null values.

public class Example
{
    public string Key { get; set; }
    public string Message { get; set; }
    public int Code { get; set; }
}
Key;Message;Code
ABC;this is a message;200
XYZ;;400

You might introduce a Boolean or Enum setting into CsvFormatterOptions? I suspect a change would be required somewhere around here:

https://github.com/WebApiContrib/WebAPIContrib.Core/blob/master/src/WebApiContrib.Core.Formatter.Csv/CsvInputFormatter.cs#L112

Of course, some CSV handling systems develop entire complicated schemes (see the PostgreSQL COPY statement, for example).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions