I'm using ServiceStack in my site to allow users to download a csv of one of the system's datasets. In the configure method of my AppHost, I'm providing a custom serializer for DateTime. It looks like this
JsConfig<DateTime>.SerializeFn = time =>
{
var result = time;
if (time.Kind == DateTimeKind.Unspecified)
{
result = DateTime.SpecifyKind(result, DateTimeKind.Local);
}
return result.ToString(CultureInfo.InvariantCulture);
};
When using the csv format all dates are being wrapped in extra quotes in the result; e.g. Result is """06/24/2015 16:22:16""" when I'd expect it to be "06/24/2015 16:22:16"
It seems to me like this must be a bug in ServiceStack serialization. Is there a way to prevent this from happening? Below is a complete example that exhibits the problem when making a request to /csv/oneway/Request
public class AppHost : AppHostBase
{
/// <summary>
/// Default constructor.
/// Base constructor requires a name and assembly to locate web service classes.
/// </summary>
public AppHost()
: base("CSVBug", typeof(MyService).Assembly)
{
}
public override void Configure(Container container)
{
JsConfig<DateTime>.SerializeFn = time =>
{
var result = time;
if (time.Kind == DateTimeKind.Unspecified)
{
result = DateTime.SpecifyKind(result, DateTimeKind.Local);
}
return result.ToString(CultureInfo.InvariantCulture);
};
}
}
public class Request
{
}
public class Response
{
public DateTime DateTime { get; set; }
}
public class MyService : Service
{
public object Any(Request reuqest)
{
return new Response()
{
DateTime = DateTime.Now
};
}
}
and Global.asax.cs
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
new AppHost().Init();
}
}
This should now be resolved with this commit which is available from v4.0.41+ that's now available on MyGet.