Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BodyToMono and BodyToFlux overrides that receive ParameterizedTypeReference [SPR-15725] #20281

spring-projects-issues opened this issue Jul 1, 2017 · 1 comment


Copy link

@spring-projects-issues spring-projects-issues commented Jul 1, 2017

Doron Gold opened SPR-15725 and commented

Sometimes the body of responses from WebClient should map to a type with generics.
Currently the bodyToMono, BodyToFlux and toEntity methods on ClientResponse and on ResponseSpec only receive Class<T> bodyType.
This does not allow for extracting bodies of a type that has generics.

Since the class BodyExtractors already has a static method: public static <T> BodyExtractor<Mono<T>, ReactiveHttpInputMessage> toMono(ParameterizedTypeReference<T> typeReference)
It seems like all there is left to do is to add bodyToMono, BodyToFlux and toEntity overrides that utilize that factory method (and the similar toFlux factory method)

Code that uses the suggested functionality would look like the following:

Mono<Page<ExampleDto>> singlePageOfExamples = webClient.get()
                .bodyToMono(new ParameterizedTypeReference<Page<ExampleDto>>() {});

singlePageOfExamples = webClient.get()
                .toEntity(new ParameterizedTypeReference<Page<ExampleDto>>() {})
                .map(responseEntity -> responseEntity.getBody())

singlePageOfExamples = webClient.get()
                .flatMap(clientResponse -> clientResponse.bodyToMono(new ParameterizedTypeReference<Page<ExampleDto>>() {}));

Affects: 5.0 RC2

1 votes, 2 watchers

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 14, 2017

Arjen Poutsma commented

Fixed in 805b715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants