spring-hateoas-examples
spring-hateoas-examples copied to clipboard
Error in this example: Hypermedia Root Controller
In this example I can't get this to work without an error RepresentationModel Needs a T.
RepresentationModel model = new RepresentationModel();
What is the right way to do this without a T in the context of a Root Controller?
/**
* @author Greg Turnquist
*/
@RestController
class RootController {
@GetMapping("/")
ResponseEntity<RepresentationModel> root() {
RepresentationModel model = new RepresentationModel();
model.add(linkTo(methodOn(RootController.class).root()).withSelfRel());
model.add(linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees"));
model.add(linkTo(methodOn(EmployeeController.class).findAllDetailedEmployees()).withRel("detailedEmployees"));
model.add(linkTo(methodOn(ManagerController.class).findAll()).withRel("managers"));
return ResponseEntity.ok(model);
}
}
I only get a warning about using a raw parameterized type. In fact, I ran api-evolution/original-server and was able to ping the server...
{
"_links": {
"self": {
"href": "http://localhost:9000/"
},
"employees": {
"href": "http://localhost:9000/employees"
}
}
}
Sorry, should have been more specific about the error. I was talking about the warning about the raw parameterized type.
Since RepresentationModel. only exist with parameterized types. Wanted to know how we should be calling it when we don't have a type, such as creating a Root Controller. EntityModel has somewhat the same issue. If you are trying to do something with generics. Multiple DTOs for the same class as an example.
Getting the warning feels like I am doing something wrong. I don't see how to get around it.