我使用spring data rest将实体公开为(分页的)rest资源.一切正常,但当我通过RestTemplate
请求数据时,我得到了一个无用的HATEOAS JSON(我没有要求).JSON似乎是一个页面资源.我可以接受,但JSON没有正确地转换成对象.里面没有content
.
Repository:
@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long>
{
List<Person> findByLastName(@Param("name") String name);
}
客户:
public List<Person> getPersons()
{
RestTemplate rt = new RestTemplate();
System.out.println(rt.getForObject(URL, PagedResources.class).getContent().size());
System.out.println(rt.getForObject(URL, PagedResources.class).getLinks().size());
System.out.println(rt.getForObject(URL, PagedResources.class).getMetadata().getTotalElements());
return new ArrayList<Person>(rt.getForObject(URL, PagedResources.class).getContent()); // <-- empty
}
System.out:
0 // getContent().size()
4 // getLinks().size()
2 // getTotalElements()
curl :
C:\...>curl http://localhost:8080/spring-jsf-rest/rest/people
{
"_links" : {
"self" : {
"href" : "http://localhost:8080/spring-jsf-rest/rest/people{?page,size,sort}",
"templated" : true
},
"search" : {
"href" : "http://localhost:8080/spring-jsf-rest/rest/people/search"
}
},
"_embedded" : {
"people" : [ {
"firstName" : "John",
"lastName" : "Rambo",
"_links" : {
"self" : {
"href" : "http://localhost:8080/spring-jsf-rest/rest/people/1"
}
}
}, {
"firstName" : "Chuck",
"lastName" : "Norris",
"_links" : {
"self" : {
"href" : "http://localhost:8080/spring-jsf-rest/rest/people/2"
}
}
} ]
},
"page" : {
"size" : 20,
"totalElements" : 2,
"totalPages" : 1,
"number" : 0
}
}
It seems like _embedded
is not mapped correctly to content?!