Skip to content

Using BeanSerializerModifier on classes extending HATEOAS ResourceSupport does not work on individual objects of the class, just on lists of objects of the class. [SPR-13608] #18186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Oct 25, 2015 · 2 comments
Assignees
Labels
status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

Abhishek Bommakanti opened SPR-13608 and commented

I'm using BeanSerializerModifier to be able to implement application-wide functionality to ignore certain JSON rendering of objects that meet a specific condition. Everything works great except for classes that extend the HATEOAS ResourceSupport class. For these classes, the functionality works as expected only if we render Collections of objects of those classes. If we try to render individual objects directly, then the custom serializer is never called.

To demonstrate, run the Spring Boot application using

mvn spring-boot:run
Then run the following commands

curl -X GET http://localhost:8080/list
curl -X GET http://localhost:8080/list-resource
The above two URLs will return the same response. This is expected behavior.

Now run the commands below

curl -X GET http://localhost:8080/person/1
curl -X GET http://localhost:8080/person-resource/1
and

curl -X GET http://localhost:8080/person/2
curl -X GET http://localhost:8080/person-resource/2
Output of these pairs of URLs is different although if everything was working correctly, they would be the same. In the second of these URLs, the custom serializer is not called.


Reference URL: https://github.com/abhishek2bommakanti/bean-init-modifier-with-hateaoas.git

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Hi Abhishek Bommakanti, thanks for the great repro project.

Based on my test, the cause of the issue is that there are 2 different ObjectMapper used, the one configured by Spring HATEOAS and the one in your application. That's why I consider this issue as a duplicate of Spring HATEOAS issue #333.

I have submitted a PR in you repro project that fix the issue by using a single ObjectMapper instance.

That said, the fix proposed in my PR is not as simple as I would like, and you are not the first one to encounter this kind of issue, so I think there is maybe something to fix on Spring HATEOAS or Spring Boot side.

I close this issue as duplicate, and think we should continue the discussion about possible fix in Spring HATEOAS issue #333.

@spring-projects-issues
Copy link
Collaborator Author

Abhishek Bommakanti commented

Hi Sébastien Deleuze,

Thanks for the quick response. The fix that you mentioned worked in the trial project I'd created, but when I tried to integrate it into the main project, I got a 'No bean named 'hazelcastInstance' is defined' error on startup. We're not using hazelcast in our application so I'm not sure why that is the case. I will try and debug further.

Regardless, do you know when either this fix or the larger fix on Spring HATEOAS or Spring Boot will be done and RELEASEd?

Thanks,
Abhishek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants