title: Decode ByteArray with spring 5 WebFlux framework
body: <p>I'm trying to use new Spring WebFlux framework with kotlin. And I can not find where I am wrong with this code (myService):</p>
  
  <pre><code>fun foo(): Flux&lt;ByteArray&gt; {
      val client = WebClient.create("http://byte-array-service")
      return client
              .get()
              .uri("/info")
              .accept(MediaType.APPLICATION_OCTET_STREAM)
              .exchange()
              .flatMapMany {
                  r -&gt; r.bodyToFlux(ByteArray::class.java)
              }
  }
  </code></pre>
  
  <p>This method returns Flux with 7893 bytes and I know there are not all bytes sent by byte-array-service. If I use old-style rest template all is ok</p>
  
  <pre><code>fun foo(): Flux&lt;ByteArray&gt; {
      val rt = RestTemplate()
      rt.messageConverters.add(
              ByteArrayHttpMessageConverter())
      val headers = HttpHeaders()
      headers.accept = listOf(MediaType.APPLICATION_OCTET_STREAM)
  
      val entity = HttpEntity&lt;String&gt;(headers)
      val r = rt.exchange("http://byte-array-service/info", HttpMethod.GET,entity, ByteArray::class.java)
      return Flux.just(r.body)
  }
  </code></pre>
  
  <p>it returns all 274124 bytes sent from byte-array-service</p>
  
  <p>here is my consumer</p>
  
  <pre><code>fun doReadFromByteArrayService(req: ServerRequest): Mono&lt;ServerResponse&gt; {
  
      return Mono.from(myService
              .foo()
              .flatMap {
                  accepted().body(fromObject(it.size))
              })
  }
  </code></pre>