spring-projects / spring-projects/spring-hateoas

Incorrect serializer used when a coroutine controller method returns a ResponseEntity

Open
#1,597 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.1k
Forks
476
PR merge metrics
No merged PRs in 30d

Description

Hello Spring Hateoas!

I have a Spring reactive application written in Kotlin which uses coroutines in controller methods. There is one use case where the correct serializer (from spring-hateoas-jsonapi) doesn't kick in: when my response is wrapped in a ResponseEntity.

I have made an example repository with controller tests to illustrate the issue. There I have four controller methods one of which doesn't return correctly formatted data to the client:

✅    fun monoEntityModel(): Mono<EntityModel<Payload>>
✅    suspend fun coroutineEntityModel(): EntityModel<Payload>
✅    fun monoResponseEntityModel(): Mono<ResponseEntity<EntityModel<Payload>>>
❌    suspend fun coroutineResponseEntityModel(): ResponseEntity<EntityModel<Payload>>

It does work fine if instead of a suspend function a Mono is returned from the controller method. It also works well if the coroutine returns data without wrapping in ResponseEntity. Just the mix of suspend fun returning ResponseEntity is problematic.

I initially thought this was a serializer issue but this has been proven wrong.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked example repository and its controller tests, comparing the four return signatures and their serialized responses. Trace the handling of a suspend method returning ResponseEntity against the working Mono and unwrapped coroutine cases. Done means the ResponseEntity coroutine case uses the same correctly formatted representation as the other working cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.