Update HATEOAS section in *Building REST services with Spring*
mqus opened this issue · comments
I just tried the mentioned tutorial and had some complications with the Spring HATEOAS sections because they still refer to Resource
and other Classes/Interfaces which were renamed by the 1.0 release of HATEOAS.
Renaming them was simple:
Resource
->EntityModel
Resources
->CollectionModel
ResourceAssembler
->RepresentationModelAssembler
toResource
->toModel
EmployeeResourceAssembler
->EmployeeRepresentationModelAssembler
(this wasn't neccessary but would be a good idea for the tutorial)
I had more difficulties with org.springframework.hateoas.mvc.ControllerLinkBuilder
/org.springframework.hateoas.server.mvc.ControllerLinkBuilder
which is now deprecated. I assume that there is no simple renamed class I can use.
How do I use it properly?
And, more importantly: would it be possible to update the tutorial?
I can try it myself when I have some time but as I'm a complete beginner in Spring (I just did the second tutorial, after all ;) ), It would probably be quicker if someone else does it.
Other than that, I'm very impressed by the tutorial and it really helped so far, thank you!
The Spring HATEOAS section of the tutorial contains deprecated code, according to IntelliJ. Specifically, EntityModel:
@GetMapping("/employees/{id}")
EntityModel<Employee> one(@PathVariable Long id) {
Employee employee = repository.findById(id)
.orElseThrow(() -> new EmployeeNotFoundException(id));
return new EntityModel<>(employee,
linkTo(methodOn(EmployeeController.class).one(id)).withSelfRel(),
linkTo(methodOn(EmployeeController.class).all()).withRel("employees"));
}
This page recommends using of(object, iterable)
instead.
This is my first exposure to Spring so I have no idea what I am doing. Can we please have the tutorial updated? Thanks.