dschulten / hydra-java

Annotate your Java beans and serialize them as json-ld with hydra
Apache License 2.0
107 stars 27 forks source link

AffordanceBuilderFactory does not use value of a @RequestParam #28

Closed rgacki closed 6 years ago

rgacki commented 7 years ago

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.

dschulten commented 6 years ago

fixed as of 0.4.1