Returning an empty "content" array when the page has no elements

Viewed 1898

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" : [ ]
    }
] 
  1. What's the idea/purpose of providing that information?
  2. Is there any way to return an empty array "content": [] when page.getContent().isEmpty()?
  3. 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?

1 Answers
Related