I am using spring-data-rest in my application. I configured repositoryRest using configureRepositoryRestConfiguration
I added the following two lines in this configuration
config.exposeIdsFor(Person.class);
config.setDefaultMediaType(MediaType.APPLICATION_JSON_UTF8);
config.useHalAsDefaultJsonMediaType(false);
Before adding this configuration my response looks as follows
{
"_embedded": {
"persons": []
},
"_links": {
"self": {
"href": "http://192.168.2.42:8082/persons/search/findByGroupId?groupId=44"
}
}
}
I am able to get the empty person list using RestTemplate as expected. But after adding the above configuration, I am getting the following response structure
{
"links": [{
"rel": "self",
"href": "http://localhost:8082/persons/search/findByGroupId?groupId=44"
}],
"content": [{
"collectionValue": true,
"relTargetType": "com.myapp.example.domain.Person",
"value": []
}]
}
with this response RestTemplate
returns a list of size 1 containing null
values for all attributes in my domain.
Can anyone help to get empty list with this structure.
I used the following code to get response from API:
restTemplate.exchange(
url,
GET,
HttpEntity.EMPTY,
parameterizedTypeReference<Resources<Person>>,
Collections.emptyMap()
);
UPDATE:
Is this a spring-data-rest bug. Because somewhere in code, instead of Person
, EmbeddedWrapper
is used as a domain type. After investigating the code, I found the "collectionValue"
, "relTargetType"
, and "value"
in JSON response are deserialized from EmbeddedWrapper
class.
Refer: EmbeddedWrappers.java