title: How to HTTP POST a Flux<String> as a JSON array using Spring's WebClient?
body: <p>How do I use Spring's reactive <code>WebClient</code> to POST a <code>Flux&lt;String&gt;</code> as a JSON array?</p>
  
  <pre><code>Flux&lt;String&gt; stringFlux = Flux.fromIterable(objects).map(MyObject::getSomeString);
  
  WebClient.create(baseUrl)
    .post()
    .uri(myUrl)
    .contentType(MediaType.APPLICATION_JSON)
    .body(stringFlux, String.class)
    .exchange()
    .flatMap(response -&gt; {
       if (response.statusCode().is2xxSuccessful()) {
         // Do something
       }
       return response.bodyToMono(Void.class);
     })
     .block();
  </code></pre>
  
  <p>This sends the request, but it's not sending it as a JSON array of strings.</p>
  
  <p>I saw that there's another <code>body()</code> signature that accepts a <code>ParameterizedTypeReference</code>, so I tried this:</p>
  
  <p><code>.body(stringFlux.collectList(), new ParameterizedTypeReference&lt;&gt;() {})</code></p>
  
  <p>but this results in a compile error actually (I'm on Java 11):</p>
  
  <p><code>Error:java: com.sun.tools.javac.code.Types$FunctionDescriptorLookupError</code>.</p>
  
  <p>Any ideas?</p>