spring-projects / spring-projects/spring-hateoas
`Enum.toString()` isn't used in links generated by `WebMvcLinkBuilder` since 1.4
@odrotbohm is already working on this.
Since May 11, 2022.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.