Gson TypeToken z dynamicznym typem elementu ArrayList

Mam ten kod:

Type typeOfObjectsList = new TypeToken<ArrayList<myClass>>() {}.getType();
List<myClass> objectsList = new Gson().fromJson(json, typeOfObjectsList);

Konwertuje łańcuch JSON na aList obiektów. Ale teraz chcę to miećArrayList z typem dynamicznym (nie tylkomyClass), zdefiniowane w czasie wykonywania.

TheArrayListtyp elementu zostanie zdefiniowany za pomocąodbicie.

Próbowałem tego:

    private <T> Type setModelAndGetCorrespondingList2(Class<T> type) {
        Type typeOfObjectsListNew = new TypeToken<ArrayList<T>>() {}.getType();
        return typeOfObjectsListNew;
    }

Ale to nie działa. To jest wyjątek:

java.sql.SQLException: Fail to convert to internal representation: {....my json....}

questionAnswers(7)

yourAnswerToTheQuestion