Skip to content

Mutation of Jackson2ObjectMapperBuilder in one injection point may affect subsequent usages #17477

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
wilkinsona opened this issue Jul 10, 2019 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@wilkinsona
Copy link
Member

Jackson2ObjectMapperBuilder is stateful and we have a few places where it's injected and mutated:

@Bean
@ConditionalOnMissingBean
public MappingJackson2XmlHttpMessageConverter mappingJackson2XmlHttpMessageConverter(
Jackson2ObjectMapperBuilder builder) {
return new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build());
}

@Bean
@Primary
@ConditionalOnMissingBean
ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
return builder.createXmlMapper(false).build();
}

@Bean
@Order(0)
@ConditionalOnBean(Jackson2ObjectMapperBuilder.class)
public RSocketStrategiesCustomizer jacksonCborRSocketStrategyCustomizer(Jackson2ObjectMapperBuilder builder) {
return (strategy) -> {
ObjectMapper objectMapper = builder.createXmlMapper(false).factory(new CBORFactory()).build();
strategy.decoder(new Jackson2CborDecoder(objectMapper, SUPPORTED_TYPES));
strategy.encoder(new Jackson2CborEncoder(objectMapper, SUPPORTED_TYPES));
};
}

As things stand, depending on auto-configuration ordering, whether or not you have Jackson's XML format on the classpath, and when precisely the Jackson2ObjectMapperBuilder is used, you may or may not get an XML mapper. Perhaps that's OK and we expect consumers of the builder to always call createXmlMapper(true|false) to meet their needs but I'm not sure that the current behaviour is intentional and I think it could be a bit brittle and confusing. #17425 is an example of that.

@wilkinsona wilkinsona added type: task A general task for: team-attention An issue we'd like other members of the team to review labels Jul 10, 2019
@philwebb philwebb added this to the 2.2.x milestone Jul 12, 2019
@philwebb philwebb added type: bug A general bug and removed for: team-attention An issue we'd like other members of the team to review type: task A general task labels Jul 12, 2019
@wilkinsona wilkinsona changed the title Review mutation of auto-configured Jackson2ObjectMapperBuilder Mutation of Jackson2ObjectMapperBuilder in one injection point may affect subsequent usages Jul 12, 2019
@philwebb
Copy link
Member

We're going to try making this a prototype bean.

@wilkinsona wilkinsona self-assigned this Jul 19, 2019
@wilkinsona wilkinsona modified the milestones: 2.2.x, 2.2.0.M5 Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants