From the AbstractRepositoryRestController#entitiesToResources
source:
if (page.getContent().isEmpty()) {
return pagedResourcesAssembler.toEmptyResource(page, domainType, baseLink);
}
When a page has no elements, Spring Data REST puts into the "content"
node an object with useless information (on my point of view) like:
"content": [
{
"relTargetType" : "my.company.ClassName",
"collectionValue" : true,
"value" : [ ]
}
]
- What's the idea/purpose of providing that information?
- Is there any way to return an empty array
"content": []
whenpage.getContent().isEmpty()
? - If it isn't possible, how then should clients handle such an unexpected format?
They parse the content
iterating over it, and map each element to some domain entity. Since it isn't a domain entity, they fail. Fetching the first element and checking it on the existence of some specific fields (e.g. relTargetType
) looks dirty, doesn't it?