spring-data-rest を使用して、エンティティを (ページ化された) 残りのリソースとして公開しています。すべて正常に動作しますが、 経由RestTemplate
でデータをリクエストすると、役に立たない HATEOAS JSON が返されます (これは求めていません)。JSON は PagedResources のようです。私はそれを受け入れることができましたが、JSON は正しくオブジェクトに変換されません。content
中身はありません。
リポジトリ:
@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
}
システム出力:
0 // getContent().size()
4 // getLinks().size()
2 // getTotalElements()
カール:
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
}
}
_embedded
コンテンツに正しくマッピングされていないようです?!