I have the following method that I am trying to use with a class that also is generic:
public static <T> T fromJson(String serializedJson, Class<T> theClazz);
And I want to deserialize a class that looks like this:
public class JsonContentWrapper<T> {
private String version;
private T content;
}
The way I would typically use the fromJson
method is like:
JsonUtil.fromJson(someJsonString, JsonContentWrapper.class)
However, since the JsonContentWrapper has that generic object content
, I'd really like to be able to do:
JsonUtil.fromJson(someJsonString, JsonContentWrapper<SomeClass>.class)
But that doesn't work. Is there a way to get a generic class and the generic it is using? I've tried something like this but didn't have much luck.
As it stands now, at least with the object I'm testing with, that T
object is getting deserialized into a LinkedHashMap
, which is wrong.