I have a Web API project with the following settings in Global.asax.cs
:
var serializerSettings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = DateTimeZoneHandling.Utc }; serializerSettings.Converters.Add(new IsoDateTimeConverter()); var jsonFormatter = new JsonMediaTypeFormatter { SerializerSettings = serializerSettings }; jsonFormatter.MediaTypeMappings.Add(GlobalConfiguration.Configuration.Formatters[0].MediaTypeMappings[0]); GlobalConfiguration.Configuration.Formatters[0] = jsonFormatter; WebApiConfig.Register(GlobalConfiguration.Configuration);
Despite all this, Json.Net cannot parse ISO durations.
It throws this error:
Error converting value "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z" to type 'System.TimeSpan'.
I'm using Json.Net v4.5.
I've tried different values such as "P1M" and others listed on the wiki page with no luck.
So the question is:
- Am I missing something?
- Or do I have to write some custom formatter?