title: Serializing and deserializing TimeSpan values to a property of type Object
body: <p>I have a class that has a field of type Object that may contain a TimeSpan object.</p>
  
  <p>I am serializing this and the deserializing this:</p>
  
  <pre><code>public class MyObject
  {
      public object myTimeSpan { get; set; }
  }
  
  ...
  
  var myObject = new MyObject { myTimeSpan = TimeSpan.FromDays(2) };
  var json = JsonConvert.SerializeObject(myObject);
  
  ...
  
  var duplicateObject = JsonConvert.DeserializeObject&lt;MyObject&gt;(json);
  </code></pre>
  
  <p>And when I do, duplicateObject.myTimeSpan contains the string "2:00:00".</p>
  
  <p>How can I get this to deserialize into a TimeSpan object?</p>
  
  <p>Two points: </p>
  
  <ol>
  <li>I'm not dealing with strings that have been serialized somewhere else. The only strings I'll be deserializing are strings that I serialized.</li>
  <li>The field has to be of type object - it might contain a string, or a DateTime, or it might contain a TimeSpan. Currently, it's only the TimeSpan I'm having problems with.</li>
  </ol>