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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -