Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simple CSV with comas can not be read #146

Open
@antonioortizpola

Description

If i generate a string field with comas, it can be serialized fine:

With this class

public class CsvPackage
{
 public int PackageCode { get; set; }
 
 public int ActivationCode { get; set; }
 
 public string PackageType { get; set; }
}

And this data:

new CsvPackage()
{
	ActivationCode = 11,
	PackageCode = 1,
	PackageName = "Comas, breaking, things"
},
new CsvPackage()
{
	ActivationCode = 22,
	PackageCode = 2
}

The write controller gets the right output:

PackageCode,ActivationCode,PackageType
1,11,"Comas, breaking, things"
2,22,

But, inserting the same test in a request gives the error:

{
"": [
"The supplied value is invalid."
]
}

If i remove the ",", everything works fine again.

Of course i had to change my config to use commas as separators:

 .AddCsvSerializerFormatters(new CsvFormatterOptions
{
 UseSingleLineHeaderInCsv = true,
 CsvDelimiter = ","
});

On the other hand, it would be great if there could be a way to set a "non-strict mode", where the found properties are mapped, and the ones that does not belong to the class could be just ignored.

This is because we have a set of common fields that are using for our system, but the sources of the csv could contain some more fields, sometimes it does not include all the fields.

Newtonsoft does the right thing filling the properties that finds, leaving the others alone, is there a reason why the behavior is not like this?

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

        AltStyle によって変換されたページ (->オリジナル) /