spring-hateoas-examples icon indicating copy to clipboard operation
spring-hateoas-examples copied to clipboard

Error in this example: Hypermedia Root Controller

Open ccit-spence opened this issue 4 years ago • 2 comments

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);
	}
}

ccit-spence avatar Dec 18 '20 09:12 ccit-spence

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

gregturn avatar Dec 18 '20 14:12 gregturn

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.

ccit-spence avatar Dec 19 '20 01:12 ccit-spence