I have the problem similar to one asked in this question however, applying the suggested solution
spring.jackson.default-property-inclusion=NON_NULL
does not stop HATEOAS from rendering links with null properties. Here's my controller declaration
@RestController
@ExposesResourceFor(Customer.class)
public class CustomerController {
// controller methods here
}
and the web config class
@Configuration
@EnableSpringDataWebSupport
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
public class DataApiWebConfiguration extends WebMvcConfigurationSupport {
// config here
}
In the Controller get method that returns a resource I declare mapping as follows
@GetMapping(value = "/customers/{id}", produces = MediaTypes.HAL_JSON_VALUE)
and then I return a Resource
Optinal<Customer> customer = customerRepository.findById(id);
return customer.map(customerResourceAssembler::toResource).map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
The CustomerResourceAssembler
extends SimpleIdentifiableResourceAssembler
as demonstrated in this spring-hateaos example.
But in the response body I still see links rendered with null properties
"links": [
{
"rel": "self",
"href": "http://localhost:8080/customers/11",
"hreflang": null,
"media": null,
"title": null,
"type": null,
"deprecation": null
}
]
this doesn't look like how a HATEOAS response should be, like in examples I see _links
not links
in the JSON