You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 :
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.
The text was updated successfully, but these errors were encountered:
I found a "kind of working thing". If I set the header of the rest template request to prs.hal-forms+json via headers.add("Accept", MediaTypes.HAL_FORMS_JSON_VALUE);, then it works so long as I don't explicitly set what the endpoint produces.
If I set produces in the GetMapping to hal+json like so: @GetMapping(produces = MediaTypes.HAL_JSON_VALUE), and update the Accept header to also accept hal+json: headers.add("Accept", MediaTypes.HAL_JSON_VALUE);, then the mapping from the response breaks and I get empty content.
I've updated my comment above. It still looks a bit weird to me and feels like something is broken here (probably my code :D but who knows)
Would really appreciate some help on this.
It does make sense in a way that setting Accept to hal-forms actually produces
{
"links": [...],
"content": [...]
}
which has exactly same structure as CollectionModel, so no wonder object mapper is able to handle it automatically
The question is there an automatic way to process CollectionModel as hal+json ? Or do I need to write my own object mapper logic?
Because the controller returns CollectionModel and produces hal+json by default unless explicitly changed via @GetMapper(produces = ...).
But consuming it via ParameterizedTypeReference<CollectionModel<EntityModel<>>> doesn't seem to work in the same way.
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 theCollectionModel
: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 :
In the debug logs, the Writing part of the body also shows correct results:
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 theParameterizedTypeReference<CollectionModel<>>
in particular.The text was updated successfully, but these errors were encountered: