Skip to content

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

Closed
@emilwihlander

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?

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