Skip to content

When returning a ResponseEntity with a Flux while the function is suspended, it fails to encode the body #27809

Closed

Description

@emilwihlander

Affects: 5.3.13

When returning a ResponseEntity<Flux<[some class]>> when the function is suspended it unnests to Flux<[some class]> (tested: 5.3.13) while it previously unnested to [some class] (tested: 5.3.11).

Example

@RestController
class Controller(val service: SomeService) {
  @GetMapping("/")
  suspend fun getStrings(): ResponseEntity<Flux<ByteBuffer>> {
    val strs: Flux<String> = service.getStrings()
    // some coroutine function is called
    val headers = HttpHeaders()
    // Set headers
    return ResponseEntity.ok().headers(headers).body(strs)
  }
}

/**
 * <= 5.3.11
 * This worked fine
 * 
 * 5.3.13
 * Throws:
 * org.springframework.http.converter.HttpMessageNotWritableException: No Encoder for [reactor.core.publisher.Flux<java.nio.ByteBuffer>] with preset Content-Type 'application/octet-stream'
 **/

This is due to the change in org.springframework.web.reactive.result.method.annotation.ResponseEntityResultHandler, where the function handleResult was changed to handle coroutinescommit. It runs nested once instead of twice, as it did before.

Mixing reactor and coroutines is bad practice, I'd guess. Therefore, I'm not certain what the desired behaviour is. Any thoughts?

Activity

  1. rrittwag commented on Dec 16, 2021

    @rrittwag

    This small project provides an example. It passes a Flux<DataBuffer> from GridFS to ResponseEntity.body.

    The unit test works when using Spring Boot 2.5.5 (Spring Framework 5.3.11), but fails on above versions.

  2. added
    theme: kotlinAn issue related to Kotlin support
    in: webIssues in web modules (web, webmvc, webflux, websocket)
    on Jan 6, 2022
  3. added this to the Triage Queue milestone on Jan 6, 2022
  4. added and removed on Feb 1, 2022
  5. modified the milestones: 5.3.16, 5.3.17 on Feb 16, 2022
  6. added a commit that references this issue on Mar 11, 2022
    a3e23cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)theme: kotlinAn issue related to Kotlin supporttype: regressionA bug that is also a regression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions