You have 2 separate issues here.
Issue the first: The <T>
in your signature is entirely eliminated. Therefore what you want (have the code write, say, List<Integer> x = get(someJsonHere);
take the notion 'hey, this code wants explicitly a list of INTEGERS, and use that at runtime to deserialize the json' is impossible as that information does not exist at runtime. The only way is that the API'd be, for example: List<Integer> x = getListOf(Integer.class, someJsonHere)
or List<Integer> x = getIntList(someJsonHere)
.
Issue the second:
For the same reason as above, the json deserializer doesn't know what to do either. java.lang.Class
instances represent classes, not the generics after them; it is not possible to represent the idea of a 'list of strings' with a java.lang.Class object. Only 'a list'.
Therefore, just like your proposed API does not work, surely whatever 'JsonDeserializer' is here, its author made something that isn't fundamentally broken and therefore offers you a way to tell it that you want a list of integers or strings or whatnot specifically.
There are 3 common ways:
[1] pass non-genericsed types whose fields are generified, so:
public class YourThing {
List<String> listOfStrings;
}
and pass YourThing.class
.
[2] more parameters!
JsonDeserializer.deserialize(yourJson, List.class, String.class);
[3] super type tokens. Looks funky, but this is legal java:
JsonDeserializer.deserialize(yourJson, new JsonDeserializerType<List<String>>() {}); // Note the trailing {}. Required.
Check the docs of the json deserializer; it'll tell you which of these strategies it offers and how to use it specifically.