I’m trying to deserialize some generic type. It works nice, but I would like to swap this piece of code out to a method.
Type listType = new TypeToken<TestResult<MyObject>>(){}.getType();
TestResult<MyObject> result = new Gson().fromJson(json, listType);
How to I do this, proving information about the type?
You can’t.
The type of a generics can’t be determinted during runtime.
An easy workaround would be to add a method to
MyObjectto return the resulting Type (like the first line of your code sample).