title: How to handle field with multiple possible types
body: <p>Is there a better way to handle a field whose value could be different types in jsonschema2pojo rather than having that field generated as <code>java.lang.Object</code> (this is all caused by legacy data that can't be migrated)</p>
  <p>For instance, if I have these JSON:</p>
  <ul>
  <li>&quot;foo&quot; is String</li>
  </ul>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;foo&quot;: &quot;bar&quot;
  }
  </code></pre>
  <ul>
  <li>&quot;foo&quot; is Array</li>
  </ul>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;foo&quot;: [&quot;bar&quot;, &quot;baz&quot;]
  }
  </code></pre>
  <p>I've tried declaring &quot;type&quot; as either a &quot;string&quot; or &quot;array&quot; in hopes the deserialization would somehow be smart enough to transform the value or force cast to either one (didn't work):</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;type&quot;:&quot;object&quot;,
    &quot;properties&quot;: {
      &quot;foo&quot;: {
        &quot;type&quot;: &quot;string&quot;
      }
    }
  }
  </code></pre>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;type&quot;:&quot;object&quot;,
    &quot;properties&quot;: {
      &quot;foo&quot;: {
        &quot;type&quot;: &quot;array&quot;
      }
    }
  }
  </code></pre>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;type&quot;: &quot;object&quot;,
    &quot;properties&quot;: {
      &quot;foo&quot;: {
        &quot;existingJavaType&quot;: &quot;java.util.List&lt;String&gt;&quot;
      }
    }
  }
  </code></pre>
  <p>How would you recommend I handle this situation? Do I have no choice but to declare &quot;foo&quot; as an Object.</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;type&quot;:&quot;object&quot;,
    &quot;properties&quot;: {
      &quot;foo&quot;: {
        
      }
    }
  }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>@JsonInclude(JsonInclude.Include.NON_NULL)
  @JsonPropertyOrder({
  &quot;foo&quot;
  })
  @Generated(&quot;jsonschema2pojo&quot;)
  public class Example {
  
  @JsonProperty(&quot;foo&quot;)
  public Object foo;
  
  }
  </code></pre>
  <p>I know I could define a second class that handle the logic for casting Object but I'd like to avoid that if possible. Such as:</p>
  <pre class="lang-java prettyprint-override"><code>public class Test extends Example {
  
    @Override
    public List&lt;String&gt; getFoo(){
     // if this.foo instanceof string return List&lt;String&gt;
     // else return this.foo
    }
  }
  </code></pre>