I am attempting to serialise some records into CSV using the ServiceStack.Text library.
I am using inheritance, specifically abstract classes and the properties on the child types are not being output. Yes I know this is a bad idea but as I have no need to deserialise the types and I'm not making a public API. Regardless, this scenario seems to be supported by the docs.
For this example:
public abstract class ResultBase
{
public int MinuteOffset { get; set; }
public double SegmentDuration { get; set; }
}
public class EventIndex : IndexBase
{
public int EventsTotal { get; set; }
public int EventsTotalThresholded { get; set; }
}
And the code to serialise:
var destination = new FileInfo("C:\\somefile.txt")
using (var stream = destination.CreateText())
{
JsvStringSerializer s = new JsvStringSerializer();
var o = s.SerializeToString(results);
stream.Write(o);
CsvSerializer.SerializeToWriter(results, stream);
}
The CSV serialiser outputs this (not what I want):
MinuteOffset,SegmentDuration
0,0
But, the JSV serialiser seems to behave as expected:
[{__type:"AnalysisBase.EventIndex, AnalysisBase",EventsTotal:0,EventsTotalThresholded:0,MinuteOffset:0,SegmentDuration:0}]
Why are there differences in the fields output, is there anyway I can get the CSV serialiser to output all child properties?