Webflux webclient and generic types

I am trying to build a generic class that will consume a REST api. The api returns lists of objects depending on the url.

I have built a Generic class

public class RestConsumer {

WebClient client;

public RestConsumer(){

//Initialize client

}

public List getList(String relativeUrl){

try{

return client

.get()

.uri(relativeUrl)

.retrieve()

.bodyToMono(new ParameterizeTypeReference> (){}

.block()

catch(Exception e){}

}

}

The problem is that T is replaced by Object at compilation time and the whole thing return a List of LinkedHashMap instead of a List of T.

I tried lots of workarounds but no luck. Any suggestions?...

Read More »

By: StackOverFlow - Monday, 19 November

Related Posts