Skip to content
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

Add method ObjectMapper.copyWith(JsonFactory) #3212

Closed
quaff opened this issue Jul 15, 2021 · 3 comments
Closed

Add method ObjectMapper.copyWith(JsonFactory) #3212

quaff opened this issue Jul 15, 2021 · 3 comments
Milestone

Comments

@quaff
Copy link

quaff commented Jul 15, 2021

It's a valid use case that reuse the same configuration over different data formats

ObjectMapper jsonObjectMapper = new ObjectMapper();
// do some configuration ...
ObjectMapper cborObjectMapper = jsonObjectMapper.copyWith(new SmileFactory());

Spring Boot configuration take affect only json format, this will make it possible to all format, for example

 @Bean 
 @ConditionalOnMissingBean(value = MappingJackson2CborHttpMessageConverter.class) 
// other conditions
 MappingJackson2CborHttpMessageConverter mappingJackson2CborHttpMessageConverter(ObjectMapper objectMapper) { 
 	return new MappingJackson2CborHttpMessageConverter(objectMapper.copyWith(new CBORFactory())); 
 } 

spring-projects/spring-boot#27319 (comment)

@cowtowncoder
Copy link
Member

I can see how this could be useful. I thought I had filed an issue like this before.

@cowtowncoder
Copy link
Member

I think #2722 is what I had in mind. Although TBH, that is for builders; "copy" methods are only available on 2.x.
So I guess these are separate.

@cowtowncoder
Copy link
Member

One thing to note: this would not work for all format: XML (jackson-dataformat-xml) for example requires XmlMapper subtype. But it would work for most formats so that's probably useful enough.

@cowtowncoder cowtowncoder added this to the 2.14.0 milestone Oct 18, 2022
@cowtowncoder cowtowncoder changed the title Provide method ObjectMapper.copyWith(JsonFactory) Add method ObjectMapper.copyWith(JsonFactory) Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants