I have this code:
Type typeOfObjectsList = new TypeToken<ArrayList<myClass>>() {}.getType();
List<myClass> objectsList = new Gson().fromJson(json, typeOfObjectsList);
It converts a JSON string to a List
of objects.
But now I want to have this ArrayList
with a dynamic type (not just myClass
), defined at runtime.
The ArrayList
's item type will be defined with reflection.
I tried this:
private <T> Type setModelAndGetCorrespondingList2(Class<T> type) {
Type typeOfObjectsListNew = new TypeToken<ArrayList<T>>() {}.getType();
return typeOfObjectsListNew;
}
But it doesn't work. This is the exception:
java.sql.SQLException: Fail to convert to internal representation: {....my json....}
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…