First of all, i'm using retrofit with gson and autovalue-gson extension
Check here : https://github.com/rharter/auto-value-gson
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 :
@AutoValue
public abstract class SocialStream<T> {
public abstract int id();
......
......
public abstract List<T> messages();
public static <T> TypeAdapter<SocialStream<T>> typeAdapter(Gson gson, TypeToken<? extends SocialStream<T>> typeToken) {
return new AutoValue_SocialStream.GsonTypeAdapter(gson, typeToken);
}
}
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.
SocialStream<FacebookPost> post = getList().get(0);
method getList() returns array of these messages and this is the line where i'm getting exception:
java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.example.model.FacebookPost
at