I am using Spring Data REST 2.5.1, Jackson 2.8.0, Spring Boot 1.3.6.
I am trying to get a simple list of entities from my repository via RestTemplate. I can get to the endpoint in the browser and get the expected HAL data. Getting a single Entity works just fine, as shown below. They all use the default SDR endpoints (for example, 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 many SO questions show, finding examples of list retrieval is a problem. I tried ParameterizedTypeReferenceto Resources, Resource, MyEntity, array, List. All without luck.
ResponseEntity<Resources<Resource<MyEntity>>> responseEntity =
new RestTemplate()
.exchange(
uri,
HttpMethod.GET,
HttpEntity.EMPTY,
new ParameterizedTypeReference<Resources<Resource<MyEntity>>>() {}
, port
)
, , Resources, Resource, List<MyEntity>, MyEntity .., ResponseEntity . :
<200 OK,Resources { content: [], links: [] },{Server=[Apache-Coyote/1.1], Content-Type=[application/json;charset=UTF-8], Transfer-Encoding=[chunked], Date=[...]}>
JSON .
{
"_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
}
}
:
@RepositoryRestResource(collectionResourceRel = "myEntities", path = "myEntity")
public interface MyEntityRepository extends PagingAndSortingRepository<MyEntity, Long>
, QueryDslPredicateExecutor<MyEntity>
, QuerydslBinderCustomizer<QMyEntity> { }
, ?