spring-projects / spring-projects/spring-hateoas

ParameterizedTypeReference<CollectionModel<EntityModel<>>> returns empty content from RestTemplate / WebClient

Open
#2,160 8 comments 1 reaction 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Feb 5, 2024.

Dominant language
Java
Stars
1.1k
Forks
476
PR merge metrics
No merged PRs in 30d

Description

I'm trying to retrieve CollectionModel<EntityModel> content from an http response body (I've tried TestRestTemplate and WebClient and both produce same results) but getting an empty content in the CollectionModel: CollectionModel { content: [], fallbackType: null, links: [] }

I can see that the response body actually has data because when I change the type to be returned as string instead of using ParameterizedTypeReference, then the response body is a valid json string like :

{
  "_embedded": {
    "entities": [...]
  },
  "_links": {...}
}

In the debug logs, the Writing part of the body also shows correct results:

[io-64000-exec-1] m.m.a.RequestResponseBodyMethodProcessor : Writing [CollectionModel { content: [EntityModel { content: MyEntity(id=1, name=Test, (truncated)...]

So the issue seems to be in the reading mapping.

Is any special configuration required for this to work?
I've searched around and couldn't find anything on how to make it work.

At the same time, ParameterizedTypeReference<EntityModel<MyEntity>> works as expected. So there's something wrong with mapping the ParameterizedTypeReference<CollectionModel<>> in particular.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.