Question: I want my response to include this:

```
"keyMaps":{
  "href":"http://localhost/api/keyMaps{/keyMapId}",
  "templated":true
 }

```

That's easy enough to achieve:

```
add(new Link("http://localhost/api/keyMaps{/keyMapId}", "keyMaps"));

```

But, of course, I'd rather use the ControllerLinkBuilder, like this:

```
add(linkTo(methodOn(KeyMapController.class).getKeyMap("{keyMapId}")).withRel("keyMaps"));

```

The problem is that by the time the variable "{keyMapId}" reaches the UriTemplate constructor, it's been included in an encoded URL:

```
http://localhost/api/keyMaps/%7BkeyMapId%7D

```

So UriTemplate's constructor doesn't recognise it as containing a variable.

How can I persuade ControllerLinkBuilder that I want to use template variables?

Answer: 
Starting with this commit:

<https://github.com/spring-projects/spring-hateoas/commit/2daf8aabfb78b6767bf27ac3e473832c872302c7>

You can now pass `null` where path variable is expected. It works for me, without workarounds.

```
resource.add(linkTo(methodOn(UsersController.class).someMethod(null)).withRel("someMethod"));

```

And the result:

```
    "someMethod": {
        "href": "http://localhost:8080/api/v1/users/{userId}",
        "templated": true
    },

```

Also check related issues: <https://github.com/spring-projects/spring-hateoas/issues/545>
We've run into the same problem. General workaround is we have our own LinkBuilder class with a bunch of static helpers. Templated ones look like this:

```
public static Link linkToSubcategoriesTemplated(String categoryId){

    return new Link(
        new UriTemplate(
            linkTo(methodOn(CategoryController.class).subcategories(null, null, categoryId))
                .toUriComponentsBuilder().build().toUriString(),
            // register it as variable
            getBaseTemplateVariables()
        ),
        REL_SUBCATEGORIES
    );
}

private static TemplateVariables getBaseTemplateVariables() {
    return new TemplateVariables(
        new TemplateVariable("page", TemplateVariable.VariableType.REQUEST_PARAM),
        new TemplateVariable("sort", TemplateVariable.VariableType.REQUEST_PARAM),
        new TemplateVariable("size", TemplateVariable.VariableType.REQUEST_PARAM)
    );
}

```

This is for exposing the parameters of a controller response of a PagedResource.

then in the controllers we call this an append a withRel as needed.