I'm using Spring Data REST 2.5.1, Jackson 2.8.0, Spring Boot 1.3.6.
I'm trying to retrieve a simple list of entities from my Repository via RestTemplate. I can hit the end point in a browser, and get the expected HAL data. Retrieving a single Entity works fine as below. These are all using the default SDR endpoints (e.g. localhost:{port}/myEntity).
ResponseEntity<Resource<MyEntity>> responseEntity =
new RestTemplate()
.exchange(
uri + "/1",
HttpMethod.GET,
HttpEntity.EMPTY,
new ParameterizedTypeReference<Resource<MyEntity>>() {}, port
)
Or new RestTemplate().getForEntity(uri + "/1", MyEntity.class, port)
As a lot of SO questions seem to indicate, finding examples of retrieving a list is a problem. I've tried the ParameterizedTypeReference
with Resources
,Resource
, MyEntity
, an array, List. All with no luck.
ResponseEntity<Resources<Resource<MyEntity>>> responseEntity =
new RestTemplate()
.exchange(
uri,
HttpMethod.GET,
HttpEntity.EMPTY,
new ParameterizedTypeReference<Resources<Resource<MyEntity>>>() {}
, port
)
When called like above with pretty much any variety of Resources
, Resource
, List<MyEntity>
, MyEntity
, etc., the ResponseEntity
is empty. Like:
<200 OK,Resources { content: [], links: [] },{Server=[Apache-Coyote/1.1], Content-Type=[application/json;charset=UTF-8], Transfer-Encoding=[chunked], Date=[...]}>
The string JSON looks like below in browser.
{
"_embedded" : {
"myEntities" : [ ... ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/myEntity"
},
"profile" : {
"href" : "http://localhost:8080/profile/myEntity"
},
"search" : {
"href" : "http://localhost:8080/myEntity/search"
}
},
"page" : {
"size" : 20,
"totalElements" : 10,
"totalPages" : 1,
"number" : 1
}
}
Repository Definition:
@RepositoryRestResource(collectionResourceRel = "myEntities", path = "myEntity")
public interface MyEntityRepository extends PagingAndSortingRepository<MyEntity, Long>
, QueryDslPredicateExecutor<MyEntity>
, QuerydslBinderCustomizer<QMyEntity> { }
Any thoughts on what I am missing?