I am using spring-data-rest to expose entities as (paged) rest resources. Everything works fine, but when I request data via RestTemplate
, I get an useless HATE
As you've discovered correctly, PagedResources
does not have an _embedded
property, that's why you don't get the content
property populated.
This dilemma can be solved in two different ways:
Providing a type that matches the representation in the first place. Thus, craft a custom class and either stick to the property names of the representation or customize it using Jackson annotations etc.
Set up a custom MappingJackson2HttpMessageConverter
and customize the ObjectMapper
to get the Jackson2HalModule
configured that Spring HATEOAS ships out of the box.
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new Jackson2HalModule());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
converter.setObjectMapper(mapper);
RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>> singletonList(converter));