title: How to modify results from a Flux with Spring Reactive
body: <p>I'm trying to convert the result of a <code>Flux</code> to confirm with Json API spec. I have my standard method which converts the <code>POJO</code> into the correct format and returns the json as a string. This works perfectly with a <code>Mono</code>.  </p>
  
  <p>However I can't workout how to handle that with the <code>Flux</code>. </p>
  
  <pre><code>@GetMapping(value = "/", produces = "application/vnd.api+json")
  @ResponseBody
  public Flux&lt;String&gt; findAll() {
      return feedItemRepository.findAll().flatMap(this::createJsonApiSpec);
  }
  
  private Mono&lt;String&gt; createJsonApiSpec(FeedItem item) {
      ObjectMapper objectMapper = new ObjectMapper();
      ResourceConverter resourceConverter = new ResourceConverter(objectMapper, FeedItem.class);
  
      JSONAPIDocument&lt;Object&gt; document = new JSONAPIDocument&lt;&gt;(item);
  
      byte[] bytes = new byte[0];
      try {
          bytes = resourceConverter.writeDocument(document);
      } catch (DocumentSerializationException e) {
          e.printStackTrace();
      }
  
      return Mono.justOrEmpty(new String(bytes));
  }
  </code></pre>
  
  <p>The find all gets all the <code>FeedItem</code>s from a reactive mongo database. Then I get confused. Using <code>flatMap</code> I can process each item at a time and convert it to a String (that confirms to the spec using the method below) but this doesn't work because each item is processed independently meaning invalid Json is returned (No <code>,</code> between each item).</p>
  
  <p>Is there another way to modify outgoing data from a Spring controller?  </p>
  
  <p><strong>Edit:</strong> I know I can make this work using</p>
  
  <pre><code>public Mono&lt;String&gt; findAll() {
      List&lt;FeedItem&gt; feedItems = feedItemRepository.findAll().collectList().block();
  
      return writeList(feedItems);
  }
  </code></pre>
  
  <p>But I'm sure that's a terrible idea to be using <code>block()</code> like that. </p>