Gson can deserialize an object like
GsonBuilder gsonBuilder = new GsonBuilder();
Myclass act = gsonBuilder.create().fromJson(someJson, this.getClass());
Here we pass the Class of the model. The question is how does Gson create an object from the Class? Are they using ClassLoader? If yes, can you help me with it? Or can we create a custom Object with tokens from the json at runtime and cast it to the required class? This question also hints at this. Can a Java class add a method to itself at runtime?