title: System Text JsonSerializer Deserialization of TimeSpan
body: <p>In researching how to deserialize a <code>TimeSpan</code> using Newtonsoft's JSON.net I came across code in my current project that did not use Json.net. It used <code>System.Text.Json.JsonSerializer</code> and <strong>appeared</strong> to not fail on the operation of deserializing the <code>TimeSpan</code> property, <em>as per the unit tests I was running</em>.</p>
  
  <p>Great I thought, <strong>.Net Core 3.1</strong> has surpassed the <em>historical</em> issue of deserializing a <code>TimeSpan</code> and all is good. So fired up a test case in the latest version of Linqpad 6 (which uses .NET Core) to verify and to my chagrin it failed.</p>
  
  <hr>
  
  <p>So the question is, can the <code>TimeSpan</code> be serialized/deserialized using either library (<em>and if so how</em>)… or is my test case below flawed in some respect?</p>
  
  <hr>
  
  <p><strong>Code</strong></p>
  
  <pre><code>public class Project { public TimeSpan AverageScanTime { get; set; } }
  </code></pre>
  
  <p><strong>Linqpad C# Code</strong></p>
  
  <pre><code>var newP = new Project() { AverageScanTime = TimeSpan.FromHours(1) };
  
  newP.Dump("New one");
  
  var json = System.Text.Json.JsonSerializer.Serialize(newP);
  
  json.Dump("JSON serialized");
  
  System.Text.Json.JsonSerializer.Deserialize&lt;Project&gt;(json)
                                 .Dump("JSON Deserialize");
  </code></pre>
  
  <p><strong>Deserialize Failure</strong></p>
  
  <p><a href="https://i.stack.imgur.com/Ma6hU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ma6hU.png" alt="enter image description here"></a></p>