Skip to content

Suspendable controller methods returning ResponseEntity are not handled #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fabienmoritz opened this issue Feb 15, 2018 · 2 comments
Closed

Comments

@fabienmoritz
Copy link

https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-ann-responseentity

The ResponseEntityResultHandler does not resolve the return type properly.

Example :

data class TestData(val value: String)

private val repo = mutableListOf<TestData>()

@RequestMapping("/testJson", produces = [MediaType.APPLICATION_JSON_UTF8_VALUE], consumes = [MediaType.APPLICATION_JSON_UTF8_VALUE])
@Controller
class JsonController {

    @GetMapping("/suspend/{value}")
    @ResponseBody
    suspend fun get(@PathVariable value: String) = repo.find { it.value == value }

// FAIL (IllegalStateException on ViewResolutionResultHandler because it is not handled by the ResponseEntityResultHandler)
    @PostMapping("/suspend")
    suspend fun createSuspend(@RequestBody value: TestData): ResponseEntity<TestData> {
        repo.add(value)
        delay(100)
        return ResponseEntity
                .created(URI("/testJson/suspend/${value.value}"))
                .body(value)
    }

// WORKS
    @PostMapping("/mono")
    fun create(@RequestBody value: TestData): Mono<ResponseEntity<TestData>> {
        repo.add(value)
        //delay(100)
        return Mono.just(ResponseEntity
                .created(URI("/testJson/suspend/${value.value}"))
                .body(value))
    }
}
@konrad-kaminski
Copy link
Owner

This an issue in Spring Core with incorrect return type of a suspending functions. I created a PR for solving it. Once it's solved it should work fine.

In the meantime I'll try to find some workaround.

@konrad-kaminski
Copy link
Owner

I'm closing this issue as this is a duplicate of #10. The workaround I mentioned can be found there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants