ServiceStack CSV serial number adding extra quotes around serialized date

I am using ServiceStack on my site to allow users to download a csv of one of the system datasets. In the configure method of my AppHost, I provide a custom serializer for DateTime. 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 wrapped in extra quotes in the result; eg Result is "" 06/24/2015 16:22:16 "" "when I expect it to be" 06/24/2015 16:22:16 "

It seems to me that this must be a bug in the Serialization of the ServiceStack. Is there a way to prevent this? Below is a complete example showing the problem when accessing / 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();
    }
}

      

+3


source to share


1 answer


This should now be resolved with this command , which is available from version 4.0.4+, is now available in MyGet .



+1


source







All Articles