Using the MvcUriComponentsBuilder to get a URL to a controller method doesnt add parameters when the value complex #33989
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: waiting-for-triage
An issue we've not yet triaged or decided on
I'm developing a Spring boot with Spring MVC web app using rest controllers. I'd like to redirect URLs that have empty parameters to the same URL but without its parameters; the idea being to explicitly remove the semantic ambiguity between an “empty filter” and “no filter”. I'm using the Links to Controllers to do this.
Sample:
In this example, the URI
/foo/bar?categories=not_empty&otherFilters=&limit=3
is expected to result in a redirect to/foo/bar?categories=not_empty&limit=3
but I am redirected to/foo/bar?limit=3
instead.The problem comes from MvcUriComponentsBuilder which only prepares the url for “simple” method parameters (Integer, String, Set).
@jcagarcia explains well how MvcUriComponentsBuilder works in this post and it allows us to to identify how these "contributors" are chosen and used (CompositeUriComponentsContributor):
In my example, it is contributor ServletModelAttributeMethodProcessor who is chosen but as he does not implement UriComponentsContributor then MvcUriComponentsBuilder will simply ignore these parameters, resulting in an incomplete URL.
You will find a ready-to-run example on this repository.
The text was updated successfully, but these errors were encountered: