Skip to content

Consider adding support for injecting a custom ObjectMapper bean #821

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
vpavic opened this issue Feb 18, 2019 · 4 comments
Closed

Consider adding support for injecting a custom ObjectMapper bean #821

vpavic opened this issue Feb 18, 2019 · 4 comments
Assignees

Comments

@vpavic
Copy link
Contributor

vpavic commented Feb 18, 2019

To my knowledge, currently it isn't possible to inject a custom, Spring HATEOAS dedicated, ObjectMapper bean into ConverterRegisteringWebMvcConfigurer as it will either work with the primary instance, or create new one:

ObjectMapper objectMapper = mapper.getIfAvailable(ObjectMapper::new);

It would be nice to have the capability to configure Spring HATEOAS to work with a non-primary ObjectMapper bean as in quite a few non-trivial apps the ObjectMapper will be used in different places and therefore with different configuration requirements.

For example, in Spring Session we have qualifiers that enable users to provide their own, Spring Session dedicated, bean definitions for infrastructure related components. As an example, see:

It would be nice if Spring HATEOAS would provide similar configuration capabilities. I'm working on a project where we're adding a new version of API (HAL based) but still have to support the previous API for quite some time - it would be nice if we could have a simple way of hooking a dedicated ObjectMapper instance into Spring HATEOAS config. At the moment we're using a BeanPostProcessor in a similar manner like described here, which obviously isn't ideal.

@vpavic
Copy link
Contributor Author

vpavic commented Mar 6, 2019

Any feedback on this? Thanks.

@odrotbohm
Copy link
Member

In #1382 we introduced callbacks on HalConfiguration and HalFormsConfiguration to customize the ObjectMapper. Does that do the trick for you?

@odrotbohm odrotbohm self-assigned this Jan 25, 2021
@odrotbohm odrotbohm added the in: configuration Configuration and setup label Jan 25, 2021
@vpavic
Copy link
Contributor Author

vpavic commented Feb 7, 2021

The originally reported problem disappeared for us when we moved to Spring HATEOAS 1.0.

To clarify: we're also using a custom media type that's based on HAL, and with 1.0 providing a first-class support custom media types, IIRC we were able to remove the BPP-based workaround by simply implementing HypermediaMappingInformation#configureObjectMapper.

For stock HAL usage I do find these new callbacks quite helpful and will certainly make use of them so many thanks for this addition. 🙂

So I assume this issue can be closed, right?

@odrotbohm
Copy link
Member

Good feedback. Glad it's working for you now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants