helun/Ektorp — Issue #69: StdObjectMapperFactory Bug
Author: jvabob
Created: 2012-02-27 21:56:30+00:00
State: open

In my application I need to register some MixIn modules to deal with 3rd party library POJO's that do not have a no arg constructor. I created a jackson ObjectMapper and registered my modules. I then created an instance of StdObjectMapperFactory and used it's setObjectMapper to put my instance of ObjectMapper into the factory. I then pass the factory to the StdCouchDbConnector constructor.

createObjectMapper works just like you would expect and passes the ObjectMapper I have given the class back out.

public synchronized ObjectMapper createObjectMapper() {
if (instance == null) {
instance = new ObjectMapper();
applyDefaultConfiguration(instance);
}
return instance;
}

However, the StdObjectMapperFactory.createObjectMapper(CouchDbConnector) method ignores the existence of the "instance" of ObjectMapper I gave it.

public ObjectMapper createObjectMapper(CouchDbConnector connector) {
ObjectMapper objectMapper = new ObjectMapper();
applyDefaultConfiguration(objectMapper);
objectMapper.registerModule(new EktorpJacksonModule(connector, objectMapper));
return objectMapper;
}

Looks to me like the to lines

ObjectMapper objectMapper = new ObjectMapper();
applyDefaultConfiguration(objectMapper);

should be replaced with something like

ObjectMapper objectMapper = createObjectMapper();

Thanks in advance!