title: System.Text: JsonSerializer.Deserialize with generics
body: <p>I am trying to make sense of the documentation:</p>
  <ul>
  <li><a href="https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-converters-how-to?pivots=dotnet-5-0" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-converters-how-to?pivots=dotnet-5-0</a></li>
  </ul>
  <p>My goal is simply to load <a href="http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.4.html" rel="nofollow noreferrer">DICOM/JSON</a> using System.Text.Json.JsonSerializer (dotnet 5.0). The steps are easy from C# to JSON:</p>
  <pre><code>private class DataElement&lt;T&gt;
  {
    public string vr { get; set; }
    public List&lt;T&gt; Value { get; set; }
  }
  [...]
  var dataset = new Dictionary&lt;string, object&gt;();
  dataset.Add(&quot;00100021&quot;, new DataElement&lt;string&gt;() { vr = &quot;LO&quot;, Value = new List&lt;string&gt;(1) { &quot;Hospital A&quot; }});
  dataset.Add(&quot;00201206&quot;, new DataElement&lt;int&gt;() { vr = &quot;IS&quot;, Value = new List&lt;int&gt;(1) { 4 } });
  dataset.Add(&quot;00101030&quot;, new DataElement&lt;double&gt;() { vr = &quot;DS&quot;, Value = new List&lt;double&gt;(1) { 72.5 } });
  string jsonString = JsonSerializer.Serialize(dataset, serializeOptions);
  File.WriteAllBytes(&quot;ds.json&quot;, Encoding.UTF8.GetBytes(jsonString));
  </code></pre>
  <p>But doing it the other way around seems much more complex.</p>
  <p>How should I implement the custom converters for those 3 possible generics (string, int or double) ?</p>