Allow custom ObjectMapper to be injected

Jackson-based session converter now allows a custom ObjectMapper to be injected.

Resolves #27.
This commit is contained in:
Greg Turnquist
2018-08-03 10:22:55 -05:00
parent 9e902ea50f
commit a2bfa4d39d
2 changed files with 36 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.security.jackson2.SecurityJackson2Modules;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.util.Assert;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
@@ -65,6 +66,12 @@ public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter
this.objectMapper.registerModules(modules);
}
public JacksonMongoSessionConverter(ObjectMapper objectMapper) {
Assert.notNull(objectMapper, "ObjectMapper can NOT be null!");
this.objectMapper = objectMapper;
}
protected Query getQueryForIndex(String indexName, Object indexValue) {
if (FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) {