我有像他这样的方法:
private <E extends RealmObject> E getFromFile(
Context context,
String jsonPath) throws IOException {
InputStream inputStream = context.getAssets().open(jsonPath);
Gson gson = new Gson();
Reader reader = new InputStreamReader(inputStream, "UTF-8");
Type typeOfT = new TypeToken<ArrayList<MyClass>>(){}.getType();
return gson.fromJson(reader, typeOfT);
}
我想问一下,是否可以从给定的类名中获取对象的ArrayList的TypeToken。像这样:
private Type getArrayListTypeFrom(Class clazz) {
return new TypeToken<ArrayList<clazz>>(){}.getType(); //how to make it work.
}
我读到了这个:Google Gson - deserialize list<class> object? (generic type),但我找不到解决方法。