I am trying to deserialize Customer
objects from a string representing a JArray
. One of the properties is a Date as string:
public class Customer: ICustomer
{
[JsonProperty(Order = 0)]
public string CreationDate{ get; set; }
}
In the JSON, the CreationDate
is set to "2015-12-31T00:00:00+01:00"
, which is the exact string I expect to find in my deserialized object.
I have written the following to deserialize the objects :
protected Collection<Customer> GetCustomers(string jsonText)
{
var jobject = JArray.Parse(jsonText);
var allClients = new Collection<Customer>()
var jsonSerializer = new JsonSerializer
{
DateParseHandling = Newtonsoft.Json.DateParseHandling.None;
};
foreach (var child in jobject.Children())
{
var customer= child.ToObject<Customer>(jsonSerializer);
allClients.Add(customer);
}
return allClients;
}
However, the value of the CreationDate
in my deserialized Customer
is equal to "12/31/2015 00:00:00"
, as if the DateParseHandling
attribute is ignored. Why?