spring-projects / spring-projects/spring-hateoas
MappingJackson2HttpMessageConverter and _halObjectMapper not working with spring-hateos 2.0.1 and spring boot 3
@odrotbohm is already working on this.
Since May 3, 2023.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
We have a legacy app which we are updating to spring boot 3. We used to use spring-hateos 0.24 RELEASE and below code to register MappingJackson2HttpMessageConverter.
public static class RestServicesConfiguration implements WebMvcConfigurer {
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
converters.add(jsonConverter());
this.configureMessageConverters(converters);
}
@Bean
public MappingJackson2HttpMessageConverter jsonConverter() {
final MappingJackson2HttpMessageConverter converter = new HalMappingJackson2HttpMessageConverter();
return converter;
}
private class HalMappingJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter {
private HalMappingJackson2HttpMessageConverter() {
setSupportedMediaTypes(Arrays.asList(
CURRENT_REST_VERSION_MEDIA_TYPE,
PREVIOUS_REST_VERSION_MEDIA_TYPE,
V2_REST_VERSION_MEDIA_TYPE
));
final ObjectMapper halObjectMapper = (ObjectMapper) beanFactory.getBean("_halObjectMapper");
final SimpleModule module = new SimpleModule("MySerializers");
module.addSerializer(Date.class, new DateSerializer());
halObjectMapper.registerModule(module);
setObjectMapper(halObjectMapper);
}
}
As we have updated to spring-hateos 2.0.1 via spring-boot-starter-data-rest 3.0.2. Upon running executing the WAR file in Tomcat 10 we are getting below exception.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonConverter' defined in com.config.AppInitializer$RestServicesConfiguration: Failed to instantiate [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter]: Factory method 'jsonConverter' threw exception with message: No bean named '_halObjectMapper' available
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.