We have a MVC.Core project where we're having problems deserializing a DateTime value from a string into a DateTime property.
Here's an example:
public class TestClass
{
public RecordStatus RecordStatus { get; set; } = RecordStatus.Active;
[System.ComponentModel.Browsable(false)]
public DateTime CreatedOn { get; private set; }
}
string s = @"{""recordStatus"":""Active"",""createdOn"":""2018-03-02T21:39:22.075Z""}";
JsonSerializerSettings jsonSettings = new JsonSerializerSettings()
{
DateFormatString = "yyyy-MM-ddTHH:mm:ss.FFFZ",
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
MissingMemberHandling = MissingMemberHandling.Ignore
};
TestClass psm = JsonConvert.DeserializeObject<TestClass>(s, jsonSettings);
The value of psm.CreatedOn is being set to
{1/1/0001 12:00:00 AM}
I've tried a bunch of different combination of values for the serializer settings with no luck. What am I missing here? I know I'm missing something obvious, but it's on of those days.
Thanks