title: Swagger oneOf type: Jackson trying to instantiate interface instead of implementation?
body: <p>I'm using the <code>oneOf</code> feature to define several possible schemas that can go into a request body property of my service. In the generated Java client code, the Java implementations of these schemas implement an interface, but when I send a request through, Jackson is trying to create an instance of the interface, instead of the concrete class.</p>
  
  <p><strong>Swagger-codegen version</strong></p>
  
  <pre><code>&lt;groupId&gt;io.swagger.codegen.v3&lt;/groupId&gt;
  &lt;artifactId&gt;swagger-codegen-maven-plugin&lt;/artifactId&gt;
  &lt;version&gt;3.0.14&lt;/version&gt;
  </code></pre>
  
  <p><strong>Swagger declaration file content</strong></p>
  
  <pre><code>schemas:
      TestRequest:
        description: 
          Test request
        type:
          object
        required:
          - criteria
        properties:
          criteria:
            oneOf:
             - $ref: '#/components/schemas/CriteriaA'
             - $ref: '#/components/schemas/CriteriaB'
      ...
      CriteriaA:
        description: Criteria A
        type: object
        required:
          - type
          - query
        properties:
          type: 
            description: A description
            type: string
            enum:
             - CriteriaA
        query:
          description: A query.
          type: object
  </code></pre>
  
  <p><strong>Steps to reproduce</strong></p>
  
  <p>The Java client code generated by swagger codegen looks like this:</p>
  
  <p>Interface:</p>
  
  <pre class="lang-java prettyprint-override"><code>public interface OneOfTestRequestCriteria {}
  </code></pre>
  
  <p>Concrete class:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Schema(description = "")
  @javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2020-01-28T13:06:29.942Z[Europe/London]")
  public class CriteriaA implements OneOfTestRequestCriteria {
  
    @JsonAdapter(TypeEnum.Adapter.class)
    public enum TypeEnum {
      CriteriaA("CriteriaA");
  
      private String value;
  
      TypeEnum(String value) {
        this.value = value;
      }
      public String getValue() {
        return value;
      }
  
      @Override
      public String toString() {
        return String.valueOf(value);
      }
      public static TypeEnum fromValue(String text) {
        for (TypeEnum b : TypeEnum.values()) {
          if (String.valueOf(b.value).equals(text)) {
            return b;
          }
        }
        return null;
      }
      public static class Adapter extends TypeAdapter&lt;TypeEnum&gt; {
        @Override
        public void write(final JsonWriter jsonWriter, final TypeEnum enumeration) throws IOException {
          jsonWriter.value(enumeration.getValue());
        }
  
        @Override
        public TypeEnum read(final JsonReader jsonReader) throws IOException {
          String value = jsonReader.nextString();
          return TypeEnum.fromValue(String.valueOf(value));
        }
      }
    }  @SerializedName("type")
    private TypeEnum type = null;
  
    @SerializedName("query")
    private Object query = null;
  
    public CriteriaA type(TypeEnum type) {
      this.type = type;
      return this;
    }
  
    @Schema(required = true, description = "")
    public TypeEnum getType() {
      return type;
    }
  
    public void setType(TypeEnum type) {
      this.type = type;
    }
  
    public CriteriaA query(Object query) {
      this.query = query;
      return this;
    }
  
    @Schema(required = true, description = "")
    public Object getQuery() {
      return query;
    }
  
    public void setQuery(Object query) {
      this.query = query;
    }
  
  
    @Override
    public boolean equals(java.lang.Object o) {
      if (this == o) {
        return true;
      }
      if (o == null || getClass() != o.getClass()) {
        return false;
      }
      CriteriaA criteriaA = (CriteriaA ) o;
      return Objects.equals(this.type, criteriaA.type) &amp;&amp;
          Objects.equals(this.query, criteriaA.query);
    }
  
    @Override
    public int hashCode() {
      return Objects.hash(type, query);
    }
  
  
    @Override
    public String toString() {
      StringBuilder sb = new StringBuilder();
      sb.append("class CriteriaA {\n");
  
      sb.append("    type: ").append(toIndentedString(type)).append("\n");
      sb.append("    query: ").append(toIndentedString(query)).append("\n");
      sb.append("}");
      return sb.toString();
    }
  
    private String toIndentedString(java.lang.Object o) {
      if (o == null) {
        return "null";
      }
      return o.toString().replace("\n", "\n    ");
    }
  
  }
  </code></pre>
  
  <p>I'm trying to use this generated client code to send a request:</p>
  
  <pre class="lang-java prettyprint-override"><code>final TestRequest testRequest = new TestRequest();
  
  final CriteriaA criteriaA = new CriteriaA ();
  criteriaA .setType(CriteriaA .TypeEnum.CriteriaA);
  criteriaA .setQuery("a query");
  
  testRequest .setCriteria(criteriaA );
  
  final ApiResponse&lt;Void&gt; apiResponse = testApi.createOrUpdateTestWithHttpInfo(testRequest);
  </code></pre>
  
  <p>Running the above client code results in this error when Jackson tries to deserialize it. It seems to be trying to construct an instance of the interface OneOfTestRequestCriteria, instead of the concrete implementation of the interface; CriteriaA:</p>
  
  <blockquote>
    <p>[Request processing failed; nested exception is
    org.springframework.http.converter.HttpMessageConversionException:
    Type definition error: [simple type, class
    com.acme.tag.models.OneOfTestRequestCriteria]; nested exception is
    com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot
    construct instance of com.acme.tag.models.OneOfTestRequestCriteria (no
    Creators, like default construct, exist): abstract types either need
    to be mapped to concrete types, have custom deserializer, or contain
    additional type information\n</p>
  </blockquote>
  
  <p>If I annotate the generated interface:</p>
  
  <pre class="lang-java prettyprint-override"><code>public interface OneOfTestRequestCriteria {}
  </code></pre>
  
  <p>with the following:</p>
  
  <pre class="lang-java prettyprint-override"><code>@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME, 
    include = JsonTypeInfo.As.PROPERTY, 
    property = "type")
  @JsonSubTypes({ 
    @Type(value = CriteriaA.class, name = "CriteriaA")
  })
  public interface OneOfTestRequestCriteria {
  
  }
  </code></pre>
  
  <p>Then the request gets deserialized correctly into CriteriaA - am I missing something in my swagger.yaml that would result in this interface not getting annotated by the codegen tool?</p>