title: How to use AutoValue to parse JSON structured as an array of objects?
body: <p>I have this JSON body:</p>
  
  <pre><code>[
      {
          "id": 0,
          "field1": "10",
          "field2": "22"
      },
      {
          "id": 1,
          "field1": "11",
          "field2": "23"
      }
  ]
  </code></pre>
  
  <p>My <code>pojoItem</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>@AutoValue
  public abstract class PojoItem{
  
      @SerializedName("field1")
      public abstract String field1();
  
      @SerializedName("id")
      public abstract int id();
  
      @SerializedName("field2")
      public abstract String field2();
  
  }
  </code></pre>
  
  <p>And my <code>pojoItemList</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>@AutoValue
  public abstract class PojoItemList{
  
      public abstract List&lt; PojoItem &gt; itemList();
  
      public static TypeAdapter&lt;PojoItemList&gt; typeAdapter(Gson gson) {
          return new AutoValue_PojoItemList.GsonTypeAdapter(gson);
      }
  }
  </code></pre>
  
  <p>I have <code>AutoValueGsonFactory</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>@GsonTypeAdapterFactory
  public abstract class AutoValueGsonFactory implements TypeAdapterFactory {
  
      // Static factory method to access the package
      // private generated implementation
      public static TypeAdapterFactory create() {
          return new AutoValueGson_AutoValueGsonFactory();
      }
  }
  </code></pre>
  
  <p>I'm using Retrofit with RxJava. I got this exception:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY</p>
  </blockquote>
  
  <p>How can I setup my POJO to read JSON as an array of objects not as collection?</p>