Empty date values aren't handled when deserializing nullable DateTime fields

Aug 1, 2009 at 11:40 PM


When I try to deserialize this data {Id: 1, Code: "A", BeginDate: ""} with JsonConvert.DeserializeObject by supplying type information, even though BeginDate is a nullable DateTime field I get an error.  I checked out the code and found that empty date string (dateText) is tried to be parsed:


if (!string.IsNullOrEmpty(_dateTimeFormat))
    return DateTime.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
    return DateTime.Parse(dateText, Culture, _dateTimeStyles);

Shouldn't it check before it parses the dateText and return null if dateText is empty or null?

Thanks in advance