Reputation: 139
On the retrieve code below, how to get Person instead of Mono or how to get Person from Mono, please ?
23.2.3 Request and Response Body Conversion
The response body can be one of the following:
Account — serialize without blocking the given Account; implies a synchronous, non-blocking controller method.
WebClient client = WebClient.create("http://example.org");
Mono<Person> result = client.get()
.uri("/persons/{id}", id).accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Person.class);
Upvotes: 2
Views: 1053
Reputation: 59211
Once you have a Mono<Person>
instance available, you have two choices:
Person person = result.block()
on it, which blocks. So you should not do that in a reactive application because this might completely block the few threads available to your application.Upvotes: 1