title: How to handle a json field, which can be one of two different types?
body: <p>I'm creating model classes for the <a href="https://cocodataset.org/#format-data" rel="nofollow noreferrer">MSCOCO annotation format</a>.</p>
  <p>There is one field in 'ObjectDetection', which can be one of two types:</p>
  <pre><code>annotation{
      &quot;id&quot;: int, 
      &quot;image_id&quot;: int, 
      &quot;category_id&quot;: int, 
      &quot;segmentation&quot;: RLE or [polygon], 
      &quot;area&quot;: float, 
      &quot;bbox&quot;: [x,y,width,height], 
      &quot;iscrowd&quot;: 0 or 1,
  }
  </code></pre>
  <p>So <code>segmentation</code> can either be a <code>List&lt;List&lt;float&gt;&gt;</code> or a <code>RunLenghtEncoding</code>, which as a class would look like this</p>
  <pre><code>public class RunLengthEncoding
  {
      [JsonProperty(&quot;size&quot;)]
      public List&lt;int&gt;? Size { get; set; }
  
      [JsonProperty(&quot;counts&quot;)]
      public List&lt;int&gt;? Counts { get; set; }
  }
  </code></pre>
  <p>Question is, how to handle this case when converting the json? Normally I would create an abstract class and inherit my two different types from that. Selection of the correct concrete type could be done in a custom converter.</p>
  <p>However, with this configuration, this doesn't seem to be possible. I also don't want to use <code>object</code>.</p>