TgetGenericClass()
のクラスを取得する必要があります。
あなたはそれを提供することができます:
Class<T> type;
public Class<T> getType() {
return this.type;
}
または実行時に取得します(安全ではありません。このサブジェットに関する多くの投稿を見つけることができると思います)
public Class<T> getType() {
return (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
次に、次のコードを使用してリスト トークンを作成します。
static TypeToken<?> getGenToken(final Class<?> raw, final Class<?> gen) throws Exception {
Constructor<ParameterizedTypeImpl> constr = ParameterizedTypeImpl.class.getDeclaredConstructor(Class.class, Type[].class, Type.class);
constr.setAccessible(true);
ParameterizedTypeImpl paramType = constr.newInstance(raw, new Type[] { gen }, null);
return TypeToken.get(paramType);
}
ここで提供したサンプルを確認してください: GSON deserialize an array of complex objects