I'm writing a library that needs a com.fasterxml.jackson.databind.ObjectMapper
instance. The user of the library should be able to provide the configuration for the ObjectMapper or the ObjectMapper instance itself. But I also add/modify some settings of the serializer without affecting the users ObjectMapper instance.
Is there any way to create a copy/clone of ObjectMapper instance?
It looks like ObjectMapper clonedInstance = new ObjectMapper(originalMapper.getFactory())
could work. But I'm not sure if there is anything what I'm missing. Will the ObjectMapper behave exactly as the original one?
Currently this is my code:
public MyLibraryClass {
private ObjectMapper internalMapper;
public MyLibraryClass(ObjectMapper mapper) {
if (mapper == null) {
internalMapper = new ObjectMapper();
} else {
internalMapper = new ObjectMapper(mapper.getFactory());
}
}
}