spring-projects / spring-projects/spring-hateoas
ResourceAssemblerSupport can't build proper links
Open
@gregturn is already working on this.
Since Mar 31, 2017.
process: waiting for feedback
type: bug
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
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"
}
}
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.