Is there a way to override Json Seralizer for DateTime format in WCF 4.0

I have an object with DateTime properties, I am wondering if there is a way to override the default format that is converted for Json responses.

+4
source share
1 answer

Unfortunately no, the date format is set to .NET 3.5 and 4.0.

There is a workaround that is not too pretty is to declare helper properties for serializing a type string, similar to the example below. It works, but you need to do this for every DateTime property in the object graph.

[DataContract] public class MyType { public DateTime MyDTProp { get; set; } [DataMember(Name = "MyDTProp")] private string strDate { get { return this.MyDTProp.ToString("yyyy/MM/dd"); } set { this.MyDTProp = DateTime.Parse(value); } } } 
+2
source

All Articles