spring-projects / spring-projects/spring-data-rest

Bug with a cast between MappingJacksonValue and RepresentationModel in HalFormsAdaptingResponseBodyAdvice?

Open
#2,146 1 comment 3 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since May 23, 2022.

status: waiting-for-triage
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Hi,

A strange behavior occurred when I tried to migrate an older springboot project. I received the following error message:

class org.springframework.http.converter.json.MappingJacksonValue cannot be cast to class org.springframework.hateoas.RepresentationModel (org.springframework.http.converter.json.MappingJacksonValue and org.springframework.hateoas.RepresentationModel are in unnamed module of loader 'app')

I had implemented a ControllerAdvice using the class AbstractMappingJacksonResponseBodyAdvice.
AbstractMappingJacksonResponseBodyAdvice class

In this case, the body is no longer just an Object, but a MappingJacksonValue.

With spring-data-rest-mvc, I have a chain of advises. HalFormsAdaptingResponseBodyAdvice uses a RepresentationModel, but AbstractMappingJacksonResponseBodyAdvice changes the type.
HalFormsAdaptingResponseBodyAdvice class

The spring-data-rest-mvc version 3.5.5 does not work with my feature that filtered the JSON with a controllerAdvise.

How can I fix it? Do you know if it's a bug?
Thank you for your help

Contributor guide

Open the contributing guide

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.