spring-projects / spring-projects/spring-hateoas

linkTo_methodOn not working on GET requested object parameter

Open
#496 14 comments 5 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

Suppose we have this method

@RequestMapping(value= "list")
public HttpEntity<ListResource> getList(
        @RequestParam(value = "text1", required = false) String text1,
        @RequestParam(value = "text2", required = false) String text2,
        @RequestParam(value = "text3", required = false) String text3,
        ...
        @RequestParam(value = "page", defaultValue = "1") Integer page,
        @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
    // ...
}

Because we have a lot of parameters, we rewrote

@RequestMapping(value= "list")
public HttpEntity<ListResource> getList(RequestObject requestObject) {
    // ...
}

public class RequestObject {
    private String text1;
    private String text2;
    private String text3;
    ...
    private Integer page;
    private Integer limit;
}

Spring MVC maps automatically the RequestObject with given parameters

But when generating the Link

final RequestObject requestObject = new RequestObject();
requestObject.setPage(1);
requestObject.setLimit(10);
requestObject.setText1("test");
return ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(ABCController.class)
                .getList(requestObject));

That doesn't return

http://localhost:8080/list?page=1&limit=10&text1=test
but only
http://localhost:8080/list

do you have any idea?

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 by reproducing the example with ControllerLinkBuilder.methodOn(ABCController.class).getList(requestObject), then inspect the methodOn and getList entry points for how a RequestObject argument is handled. Done means the generated link includes the populated page, limit, and text1 query parameters instead of only the path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.