如何在spring-data-rest中使用没有HAL响应结构的空集合

Ach*_*ius 7 spring-mvc spring-data-rest spring-hateoas spring-4

我在我的应用程序中使用spring-data-rest.我使用configureRepositoryRestConfiguration配置了repositoryRest

我在此配置中添加了以下两行

config.exposeIdsFor(Person.class);
config.setDefaultMediaType(MediaType.APPLICATION_JSON_UTF8);
config.useHalAsDefaultJsonMediaType(false);
Run Code Online (Sandbox Code Playgroud)

在添加此配置之前,我的响应如下所示

{
  "_embedded": {
    "persons": []
  },
  "_links": {
    "self": {
      "href": "http://192.168.2.42:8082/persons/search/findByGroupId?groupId=44"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我可以按预期使用RestTemplate获取空人列表.但是在添加上面的配置之后,我得到了以下响应结构

{
  "links": [{
    "rel": "self",
    "href": "http://localhost:8082/persons/search/findByGroupId?groupId=44"
  }],
  "content": [{
    "collectionValue": true,
    "relTargetType": "com.myapp.example.domain.Person",
    "value": []
  }]
}
Run Code Online (Sandbox Code Playgroud)

使用此响应RestTemplate返回一个大小为1的列表,其中包含null我域中所有属性的值.

任何人都可以帮助获得这种结构的空列表.

我使用以下代码从API获取响应:

restTemplate.exchange(
    url, 
    GET, 
    HttpEntity.EMPTY, 
    parameterizedTypeReference<Resources<Person>>, 
    Collections.emptyMap()
);
Run Code Online (Sandbox Code Playgroud)

更新:

这是一个spring-data-rest bug.因为某处代码,而不是Person,EmbeddedWrapper用作域类型.调查代码后,我发现"collectionValue","relTargetType""value"在JSON响应是从反序列化EmbeddedWrapper类.

参考:EmbeddedWrappers.java