This question used to be titled "Spring 5 Reactive WebClient consuming HAL+JSON HATEOAS PagedResources", but the new title is more appropriate.
The following code works perfectly with RestTemplate (the parametrized type is being returned from a HATEOAS/HAL PagedResource served from Spring DataREST):
// use exchange with ParameterizedTypeReference
ResponseEntity<PagedResources<Foo>> responseEntity =
restTemplate.exchange("/foos", HttpMethod.GET, null,
new ParameterizedTypeReference<PagedResources<Foo>>() {},
randomServerPort, 0, 100);
// then the actual list of foos can be obtained like so
PagedResources<Foo> resources = responseEntity.getBody();
List<foo> foos = new ArrayList(resources.getContent());
This is NOT working with Spring 5 Reactive WebClient:
public Mono<PagedResources<Foo>> getFoos() {
return client.get()
.uri("/foos").accept(MediaTypes.HAL_JSON)
.retrieve()
.bodyToMono(new ParameterizedTypeReference<PagedResources<Foo>>(){});
}
The controller code that calls the service method above is:
@GetMapping("/foos")
public Mono<PagedResources<Foo>> getFoos() {
return dataService.getFoos();
}
The result with curl is:
{"links":[],"content":[],"page":null}
After a lot of research, the code above should work as the parametrized type should be passed along to Jackson just like in the RestTemplate's case shown above.
This is looking now more like a bug. But before filing one I would like to see if someone has WebClient bodyToXXX working with parametrized types (i.e. ParameterizedTypeReference, Super Type Tokens, etc.)
Note there is a test for this in the WebClient code but maybe the embedded type ref (PagedResources) is not currently supported or has a bug:
Bug filed: https://jira.spring.io/browse/SPR-16715