0

We had the same Issue as mentioned in here and used the provided workaraound with a resourceprocessor.

Spring Data REST returns EmptyCollectionEmbeddedWrapper instead of empty collection

now we moved on to SpringBoot 2.3, which updates its dependencies to HATEOAS 1.x and those brought a lot of breaking changes. following the migrationguide for HATEOAS 1.x fixed the compiler errors, though left us with runtime exceptions when Spring is trying to cast classes but cannot.

we would love to have an generic approach to layer no matter which rest endpoint and return an empty array instead of the CollectionWrapper with its null attributes. adjusting it for each model is not maintainable.

EDIT: we are already setting the config to return always JSON, though it still returns those "null-Objects"

config.setReturnBodyOnCreate(true).setReturnBodyOnUpdate(false).setDefaultMediaType(MediaType.APPLICATION_JSON_UTF8);

for example: here the search has no hits, the content-array is still returned with one element which is parsed into a "null-Object"

{
  "links": [
    {
      "rel": "self",
      "href": "http://api.service.test/service/campaigns/search/findByActive?active=false&page=0&size=20"
    }
  ],
  "content": [
    {
      "relTargetType": "com.test.service.campaign.model.Campaign",
      "collectionValue": true,
      "value": [
      ],
      "rel": null
    }
  ],
  "page": {
    "size": 20,
    "totalElements": 0,
    "totalPages": 0,
    "number": 0
  }
}
NoKnow
  • 11
  • 2
  • you might just be looking for using spring data REST without HAL: https://stackoverflow.com/questions/37971312/spring-data-rest-in-plain-json-not-hal-format. – p.streef Jul 14 '20 at 11:52
  • @p.streef we already set it to JSON, so the "problem" seems to be different – NoKnow Jul 21 '20 at 07:32

0 Answers0