spring-projects / spring-projects/spring-hateoas
LinkBuilder doesn't include Matrix Variables
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
If an endpoint uses Matrix Variables and you try to create a link to this method, the passed matrix variables aren't inserted into the link. The issue popped up in this Stack Overflow question.
See the following endpoint as an example:
@RequestMapping(value = "/matrix", method = RequestMethod.GET)
public HttpEntity example(
@MatrixVariable String first,
@MatrixVariable(required = false) String second) {
return new HttpEntity<>("first=" + first + " second=" + second);
}
Using linkTo(methodOn(MvcController.class).example("First", "Second")).withSelfRel().getHref(); produces http://localhost:8090/matrix
whereas it should be http://localhost:8090/matrix;first=First;second=Second
As I outlined in the SO answer it is most likely that the UriBuilder implementation just doesn't consider matrix parameters:
- See this part of the UriTemplate. It uses different variable types to build the Uri. A matrix parameter isn't one of them.
- See the VariableType enum, which was used to do the switch on. There is also no matrix param.
There should be a possibility to create links with matrix variables.
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.
Research direction
Start with UriTemplate.java around the referenced UriBuilder logic and TemplateVariable.java around the VariableType enum. Trace how linkTo(methodOn(...).example("First", "Second")) builds its URI, then verify that the resulting href includes ;first=First;second=Second for the example endpoint.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100