spring-projects / spring-hateoas-examples

Collection of examples on how (and why) to build hypermedia-driven apps with Spring HATEOAS
Apache License 2.0
377 stars 184 forks source link

Error in this example: Hypermedia Root Controller #37

Open ccit-spence opened 3 years ago

ccit-spence commented 3 years ago

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);
    }
}
gregturn commented 3 years ago

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"
    }
  }
}
ccit-spence commented 3 years ago

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.