2

Closed

Iso Durations are not serialized/desrialized properly

description

Given the following snippet,
        var settings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.IsoDateFormat };
        settings.Converters.Add(new IsoDateTimeConverter()); 

        var duration = new TimeSpan(0, 1, 0);
        Debug.WriteLine(JsonConvert.SerializeObject(duration, settings));
Outputs: "00:01:00"
Should output: "PT1M"
        Debug.WriteLine(JsonConvert.DeserializeObject("{\"Duration\": \"PT1M\"}", settings));
Fails: Error converting value "PT1M" to type 'System.TimeSpan'. Path 'Duration', line 1, position 19.
Closed May 4, 2013 at 3:12 AM by JamesNK
Create a JsonConverter that serializes TimeSpans to the format you want.

comments