title: Retrofit 2.0, Jackson and polymorphism: Could not find creator property with name <...>
body: <p>I'm currently consuming a REST API with RetroFit &amp; Jackson. Consider the following response JSON when retrieving users based on a search query when:</p>
  
  <p>One result was found</p>
  
  <pre><code>{
      name: "API name",
      results: {
          count: 1
          users: {
              username: "username",
              age: 15
          }
      }
  }
  </code></pre>
  
  <p>Multiple results were found</p>
  
  <pre><code>{
      name: "API name",
      results: {
          count: 2,
          users: [{
              username: "username1",
              age: 18
          }, {
              username: "username2",
              age: 19
          }]
      }
  }
  </code></pre>
  
  <p>As you can see, the users-property contains dynamic JSON: based on the found results, the value of "users" could either be a list of user objects, or 1 user object.</p>
  
  <p>As such, I've designed my Java POJOs using polymorphism, as follows:</p>
  
  <pre><code>public class UserResponse {
      @JsonProperty("name")
      private String apiName
  
      @JsonProperty("results")
      private AResultList resultList
  
      //Getters &amp; Setters
  
      //Constructor
      @JsonCreator
      public UserResponse(@JsonProperty("name") String name, @JsonProperty("results") AResultList r) {
          this.apiName = name;
          this.resultList = r;
      }
  }
  
  @JsonTypeInfo(
          use = JsonTypeInfo.Id.NAME,
          include = JsonTypeInfo.As.PROPERTY,
          property = "classType"
          )
  @JsonSubTypes({
      @JsonSubTypes.Type(value = ResultObject.class, name="ResultObject"),
      @JsonSubTypes.Type(value = ResultList.class, name="ResultList")
  })
  public abstract class AResultList {
      @JsonProperty("count)
      private long totalCount;
  
      //Getters &amp; Setters
  
      //Constructors
      @JsonCreator
      public AResultList(@JsonProperty("count) long count) {
          this.totalCount = count;
      }
  }
  
  public class ResultObject extends AResultList {
      @JsonProperty("users")
      private User user;
  
      //Getters &amp; Setters
  
      //Constructor
      @JsonCreator
      public ResultObject(@JsonProperty("count) long count, @JsonProperty("users") User u) {
          super(count);
  
          this.user = u;
      }
  }
  
  public class ResultList extends AResultList {
      @JsonProperty("users")
      private List&lt;User&gt; users;
  
      //Getters &amp; Setters
  
      //Constructor
      @JsonCreator
      public ResultObject(@JsonProperty("count) long count, @JsonProperty("users") List&lt;User&gt; u) {
          super(count);
  
          this.users = u;
      }
  }
  
  public class User {
      @JsonProperty("username")
      private String username;
  
      @JsonProperty("age")
      private long userAge;
  
      //Getters &amp; Setters
  
      //Constructor
      @JsonCreator
      public User(@JsonProperty("username") String u, @JsonProperty("age") long a) {
          this.userAge = a;
          this.username = u;
      }
  }
  </code></pre>
  
  <p>For your information: A snippet for instantiating RetroFit</p>
  
  <pre><code>ObjectMapper o = new ObjectMapper();
  
  retrofit = new Retrofit.Builder()
                  .baseUrl(BASE_URL)
                  .addConverterFactory(JacksonConverterFactory.create(o))
                  .client(okClient)
                  .build();
  </code></pre>
  
  <p>Trying to retrieve this information, however, results in the following error:</p>
  
  <pre><code>com.fasterxml.jackson.databind.JsonMappingException: Could not find creator property with name 'count' (in class org.namespace.AResultList)
  at [Source: java.io.InputStreamReader@41cd2648; line: 1, column: 1]
  </code></pre>
  
  <p>I've been stuck on this "dynamic data" problem for 2 days now. Already tried to use GSON library and a lot of other things but to no avail. So I'd like to ask:<br>
  - Why is Jackson causing this? Is this a bug? Some users have already asked this question but the provided solutions did not work for my case.<br>
   - Is this the correct way of handling data of which part is dynamic?</p>
  
  <p>I've tested my code without the use of polymorphic classes (and only retrieving 1 User from the API) and object maps perfectly. The problem is caused by the polymorphism, but I cannot figure out how to fix it.</p>