Próbuję do prostego, restowego api(opartego o spring boot'a) wpleść hateoas by wskoczyć na wyższy poziom zajebistości.
Zależność do pom'a dodana
CustomerDTO rozszerza odpowiednią klasę (RepresentationModel<CustomerDto>, w kontrolerze mapuję encję z bazy na dto za pomocą mapstructa)
W kontrolerze tworzę link, obiekt typu EntityModel<> i to zwracam opakowane w ResponseEntity.
Problem w tym, że w postmanie (i curl'u) wraca jedynie {} i status 200.
Jeśli przerobię kontroler tak, by zwracał zwyczajne CustomerDto (opakowane w ResponseEntity) to wszystko działa.
Co więcej w debugerze obiekt resource wygląda ok, ma wszystkie pola i poprawny link.
Kontroler:
@JsonView(View.Public.class)
@GetMapping("/{customerId}")
public ResponseEntity<EntityModel<CustomerDto>> getCustomer(@PathVariable Long customerId) {
Link link = WebMvcLinkBuilder.linkTo(CustomerController.class).slash(customerId).withSelfRel();
Long userId = userService.getCurrentLoggedUserId();
Customer customer = customerService.getCustomer(userId, customerId);
CustomerDto customerDto = customerMapper.convertCustomerToCustomerDto(customer);
EntityModel<CustomerDto> resource = new EntityModel<>(customerDto, link);
return new ResponseEntity<>(resource, HttpStatus.OK);
}
Aktualizacja:
Winna była adnotacja @JsonView:
https://github.com/spring-projects/spring-hateoas/pull/387