spring-projects / spring-projects/spring-hateoas

LinkBuilder doesn't include Matrix Variables

Open
#437 2 comments 1 reaction 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

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:

  1. See this part of the UriTemplate. It uses different variable types to build the Uri. A matrix parameter isn't one of them.
  2. 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

  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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.