title: The correct way to map a REST response to a Mono<SomeClass> using WebClient/ Spring Boot 2
body: <p>I have a controller which is asking a service to reach a service endpoint to get a list of account numbers, then reach out to another service for each account number and retrieve additional data about that account. The 'happy path' essentially looks like this:</p>
  <p>CONTROLLER</p>
  <pre><code>@ApiOperation(value = &quot;getRelatedAccounts&quot;)
  @GetMapping(value = &quot;/relatedaccounts&quot;)
  public ResponseEntity&lt;RelatedAccounts&gt; getRelatedAccounts(@RequestParam String accountNumber) {
      return new ResponseEntity&lt;&gt;(myService.getRelatedAccounts(accountNumber), HttpStatus.OK);
  }
  </code></pre>
  <p>SERVICE</p>
  <pre><code>public RelatedAccounts getRelatedAccounts(String accountNumber) {
      // blah blah, hit the endpoint and get my response of a list of account numbers in relatedAccountsList
      Flux&lt;AccountInformation&gt; accountInfoFlux = Flux.fromIterable(relatedAccountsList)
          .parallel()
          .runOn(Schedulers.elastic())
          .flatMap(this::getAccountInformation)
          .ordered(Comparator.comparing(RelatedAccounts::getCorrectOrder)) // blah blah, convert from ParallelFlux to Flux
  }
  </code></pre>
  <p>OTHER SERVICE</p>
  <pre><code>public Mono&lt;AccountInformation&gt; getAccountInformation(String accountNumber) {
      WebClient webClient = WebClient.builder()
              .baseUrl(&quot;http://myurl.com&quot;)
              .build();
  
      return webClient
              .get()
              .uri(uriBuilder -&gt; uriBuilder
                      .queryParam(&quot;accountNumber&quot;, accountNumber)
                      .build()
              ).retrieve()
              .bodyToMono(AccountInformation.class) // This doesn't work for us, we get a very complex object as a response and need to parse a few fields.
  }
  </code></pre>
  <p>I've spent all day on Google and I don't see anyone else parsing the response they get back, they just magically map it directly onto a perfectly created class. We don't have that option, we need to pluck the accountName from the response body and put it in the AccountInformation object. Does anyone have any idea how to do this?</p>