I found many similar questions, but none of them helped.
It works:
public class Assets<T> { public T getAndDeserializeAsset(String endpoint, String assetId, Client client){ Response response = client.get(endpoint+assetId); Gson gson = new Gson(); T asset = gson.fromJson(response.body, new TypeToken<Email>(){}.getType()); return asset; }
}
It does not mean:
public class Assets<T> { public T getAndDeserializeAsset(String endpoint, String assetId, Client client){ Response response = client.get(endpoint+assetId); Gson gson = new Gson(); T asset = gson.fromJson(response.body, new TypeToken<T>(){}.getType()); return asset; }
}
I did this according to the official documentation, so I have no idea why this is not working.
Error:
Exception in thread "main" java.lang.ClassCastException: com.rest.api.Response cannot be cast to model.Email at main.Main.main(Main.java:34)
source share