title: AutoValue: ClassCastException: LinkedTreeMap cannot be cast to
body: <p>First of all, i'm using retrofit with gson and autovalue-gson extension</p>
  
  <p>Check here : <a href="https://github.com/rharter/auto-value-gson" rel="nofollow">https://github.com/rharter/auto-value-gson</a></p>
  
  <p>In API i have a different models, where API returns json with id, description etc and also array of messages, but these messages may vary depending on what type of social media i want to (facebook, twitter, instagram etc...). So i made model like this :</p>
  
  <pre><code>@AutoValue
  public abstract class SocialStream&lt;T&gt; {
    public abstract int id();
    ......
    ......
  
    public abstract List&lt;T&gt; messages();
  
    public static &lt;T&gt; TypeAdapter&lt;SocialStream&lt;T&gt;&gt; typeAdapter(Gson gson, TypeToken&lt;? extends SocialStream&lt;T&gt;&gt; typeToken) {
      return new AutoValue_SocialStream.GsonTypeAdapter(gson, typeToken);
    }
  }
  </code></pre>
  
  <p>As you can see i also passed typetoken to AutoValue typeAdapter, and everything seems to work, i already logged whole json, but problem occurs when i try to use it as my model.</p>
  
  <pre><code>SocialStream&lt;FacebookPost&gt; post = getList().get(0);
  </code></pre>
  
  <p>method getList() returns array of these messages and this is the line where i'm getting exception: </p>
  
  <pre><code>java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.example.model.FacebookPost
  at 
  </code></pre>