Skip to content

Please provide a way to clone an ObjectMapper #28

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
rzio opened this issue Jul 4, 2012 · 4 comments
Closed

Please provide a way to clone an ObjectMapper #28

rzio opened this issue Jul 4, 2012 · 4 comments

Comments

@rzio
Copy link

rzio commented Jul 4, 2012

We need a way to clone an ObjectMapper. The user case is:
At some times we need a ObjectMapper which has a slightly different configuration that the one that we use though the system.

In Jackson 1.9.1 we did this by
ObjectMapper o1= new ObjectMapper()
.setSerializationConfig(objectMapper.getSerializationConfig()
.with(SerializationConfig.Feature.INDENT_OUTPUT));

I couldn't find a way to reproduce this in Jackson 2.

We cannot use ObjectReader/ObjectWriter for this, since we use both databinding and the TreeModel and ObjectWriter doesn't have support for TreeModel.

@cowtowncoder
Copy link
Member

Right, 2.0 sort of hides access to serialization/deserialization config objects.
I'll have to think of best way to do this; one possibility would be to just implement clone() properly, another to have something similar but named explicitly (copyOf())

@rzio
Copy link
Author

rzio commented Jul 5, 2012

ObjectMapper o1= objectMapper.clone().configure(SerializationFeature.INDENT_OUTPUT));

or
ObjectMapper o1= ObjectMapper.copyOf(objectMapper).configure(SerializationFeature.INDENT_OUTPUT));

Both seem reasonable to me :)

@cowtowncoder
Copy link
Member

Right, those seem like obvious choices. I may ask others on dev list for their input just for fun.

@cowtowncoder
Copy link
Member

Implemented as 'ObjectMapper.copy()'. Required quite a bit more work than I expected; had to add JsonFactory.copy() as well, tested etc. But should work more reliably than the old method, as well; i.e. copy all state, unshare.

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