In GSON to get a list of objects you do
Gson gson = new Gson();
Type token = new TypeToken>(){}.getType();
return gson.fromJson(json
This work for everything. e.g. map which has a key and value generic.
CustomType type = new CustomType(Map.class, String.class, Integer.class);
So no more TokenType.
class CustomType implements ParameterizedType {
private final Class> container;
private final Class>[] wrapped;
@Contract(pure = true)
public CustomType(Class> container, Class>... wrapped) {
this.container = container;
this.wrapped = wrapped;
}
@Override
public Type[] getActualTypeArguments() {
return this.wrapped;
}
@Override
public Type getRawType() {
return this.container;
}
@Override
public Type getOwnerType() {
return null;
}
}