1

consider following class:

class Foo {
    public string bar { get; set; }
    public string rab { get; set; }

    public override string ToString()
    {
        return string.Format("[Foo bar={0}, rab={1}]", bar, rab);
    }
}

And following code:

var csv1 =
    "bar,rab" + Environment.NewLine +
    "a,b" + Environment.NewLine +
    "c,d" + Environment.NewLine +
    "e,f" + Environment.NewLine;

var csv2 =
    "xbar,xrab" + Environment.NewLine +
    "a,b" + Environment.NewLine +
    "c,d" + Environment.NewLine +
    "e,f" + Environment.NewLine;

Console.WriteLine(CsvSerializer.DeserializeFromString<List<Foo>>(csv1).First());

CsvConfig<TMDBEntity>.CustomHeadersMap = new Dictionary<string, string> {
    {"bar", "xbar"},
    {"rab", "xrab"}
};

Console.WriteLine(CsvSerializer.DeserializeFromString<List<Foo>>(csv2).First());

It is printing:

[Foo bar=a, rab=b]
[Foo bar=, rab=]

while I would expect it to print

[Foo bar=a, rab=b]
[Foo bar=a, rab=b]

Why is it not picking up the custom headers using xbar and xrab?

ServiceStack.Text version is 4.5.14.0

jesus_
  • 11
  • 1
  • There is a similar post: https://stackoverflow.com/questions/36851708/deserialize-csv-with-customheaders-using-servicestack-text. The statci CsvConfig object writes the dictionary in the CsvWriter and CsvReader, try "CcvConfig.CustomHeadersMap = ...." for your example. If wont use theheaders ofthe TMDBEntity – Patrick Artner Nov 18 '17 at 00:20

1 Answers1

2

This issue should be resolved from this commit which is available from ServiceStack v5.0.0 that's now available on MyGet.

Note you need to configure CsvConfig<Foo> in order to change how Foo is deserialized, e.g:

CsvConfig<Foo>.CustomHeadersMap = new Dictionary<string, string> {
    {"bar", "xbar"},
    {"rab", "xrab"}
};
mythz
  • 141,670
  • 29
  • 246
  • 390