Skip to content

ResourceAssemblerSupport can't build proper links #571

@gregturn

Description

@gregturn

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"
      }
    }
  }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions