mercredi 10 juin 2015

Deserializing Generic Types from a ClassLouder class with GSON

I´m trying to parse a JSON file using GSON, the problem is that I´m using a Class that it was previously loaded by ClassLoader.

File root = new File("./build/classes");
URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() });

Class<?> loadedClass = Class.forName("events.Source", true,classLoader);


// JSON --> Java "Get the actual type"
Type listType = new TypeToken<ArrayList<loadedClass>>() {}.getType(); 

Gson gson = new Gson();

ArrayList<loadedClass> resourcesList = gson.fromJson(jsonString, listType);

That returns a com.google.gson.internal.LinkedTreeMap not a List of my own loadedClass. Any help?





Aucun commentaire:

Enregistrer un commentaire