This project has moved and is read-only. For the latest updates, please go here.

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

Aug 2, 2009 at 12:40 AM


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