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>
With latest versions of `spring-hateoas` you can do the following:

```
UriComponents uriComponents = UriComponentsBuilder.fromUri(linkBuilder.toUri()).build();
UriTemplate template = new UriTemplate(uriComponents.toUriString())
   .with("keyMapId", TemplateVariable.SEGMENT);

```

will give you: `http://localhost:8080/bla{/keyMapId}",`