java - Passing method generic type to internal call -


i trying create method generics unmarshal json lists lists containing pojos. snippet below compiles , runs, @ runtime getting list<custompojo> filled hashmap instances, type t not passed along typereference constructor falls hashmap guess.

public static <t> list<t> getlist(string endpoint) throws ioexception {     httpget request = new httpget(server_address + endpoint);     closeablehttpresponse response = httpclient.execute(request);     try {         statusline statusline = response.getstatusline();         if (statusline.getstatuscode() == 200) {             return mapper.readvalue(response.getentity().getcontent(), new typereference<list<t>>() { });         }     } {         response.close();     }     return null; } 

am on right track or not achievable using generics?

try use like:

    mapper.readvalue(response.getentity().getcontent(),     mapper.gettypefactory().contructcollectiontype(list.class, cls); 

where cls class<t> should works.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -