dschulten/hydra-java

AffordanceBuilderFactory does not use value of a @RequestParam

rgacki opened this issue · 1 comments

I have a controller method with arguments annotated with @RequestParam, like this:

@GetMapping(produces = MediaType.TEXT_HTML_VALUE)
public ModelAndView showAsHtml(final @RequestParam("q") String query,
                               final @RequestParam(value = "offset", defaultValue = "0") Long offset,
                               final Locale locale) {
  // do stuff
}

Now I build an Affordance that is an URI template:

AffordanceBuilder.linkTo(AffordanceBuilder.methodOn(MyController.class)
        .showAsHtml(null, null, null))
        .rel("something")
        ...;

The serialized hydra:IriTemplate will look like this:

{
    "@type": "hydra:IriTemplate",
    "hydra:template": "http://localhost:8080/something{?query}",
    "hydra:mapping": [
      {
        "@type": "hydra:IriTemplateMapping",
        "hydra:variable": "query",
        "hydra:required": true,
        "hydra:property": "query"
      }
    ]
  }

So the variable "query" is wrong. It should be "q" as defined by the @RequestParam.

fixed as of 0.4.1