spring-projects / spring-projects/spring-hateoas

`Enum.toString()` isn't used in links generated by `WebMvcLinkBuilder` since 1.4

Open
#1,736 5 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since May 11, 2022.

process: waiting for feedback
Dominant language
Java
Stars
1.1k
Forks
476
PR merge metrics
No merged PRs in 30d

Description

I'm using WebMvcLinkBuilder to generate links to controller methods with specific predefined parameters represented by a list of enums. These enums have custom toString() implementations to provide required labels for given API calls. However, it's not used since 1.4 resulting in incorrect links.

Simplified example:

enum class Words(private val text: String) {
    HELLO("Hello,"),
    WORLD("world!");

    override fun toString(): String {
        return text
    }
}
val invocation = WebMvcLinkBuilder.methodOn(TestController::class.java)
        .get(listOf(Words.HELLO, Words.WORLD))
val actualLink = WebMvcLinkBuilder.linkTo(invocation).withSelfRel().href

Currently, since 1.4, they are represented using their name():
/?words=HELLO&words=WORLD

However, before 1.4, enums were converted using their toString() implementation, generated link was:
/?words=Hello,&words=world!

Sample project with unit test:
demo-hateoas.zip

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.