-
Notifications
You must be signed in to change notification settings - Fork 472
Open
Description
By using slash()
, ResourceAssemblerSupport is failing to properly take into account the full path of a Spring MVC route.
protected D createResourceWithId(Object id, T entity, Object... parameters) {
Assert.notNull(entity, "Entity must not be null!");
Assert.notNull(id, "Id must not be null!");
D instance = instantiateResource(entity);
instance.add(linkTo(controllerClass, parameters).slash(id).withSelfRel());
return instance;
}
This fails for a controller like this:
@GetMapping("/employees/{id}")
public ResponseEntity<?> findOne(@PathVariable String id) {
return ResponseEntity.ok(
assembler.toResource(repository.findOne(Long.valueOf(id))));
}
In this situation, the route mapping is /employees/1, but yields this:
{
"id": 1,
"lastName": "Baggins",
"firstName": "Frodo",
"role": "ring bearer",
"_links": {
"self": {
"href": "http://localhost:8080/1"
}
}
}