Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
import org.springframework.security.jackson2.SecurityJackson2Modules;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

/**
* {@code AbstractMongoSessionConverter} implementation using Jackson.
*
* @author Jakub Kubrynski
* @author Greg Turnquist
* @author Michael Ruf
* @author TiQuan Hu
* @since 1.2
*/
public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter {
Expand Down Expand Up @@ -93,9 +95,12 @@ protected Query getQueryForIndex(String indexName, Object indexValue) {
}

private ObjectMapper buildObjectMapper() {

ObjectMapper objectMapper = new ObjectMapper();
configureObjectMapper(objectMapper);
return objectMapper;
}

public static void configureObjectMapper(ObjectMapper objectMapper) {
// serialize fields instead of properties
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
Expand All @@ -105,11 +110,9 @@ private ObjectMapper buildObjectMapper() {

objectMapper.setPropertyNamingStrategy(new MongoIdNamingStrategy());

objectMapper.registerModules(SecurityJackson2Modules.getModules(getClass().getClassLoader()));
objectMapper.registerModules(SecurityJackson2Modules.getModules(ClassUtils.getDefaultClassLoader()));
objectMapper.addMixIn(MongoSession.class, MongoSessionMixin.class);
objectMapper.addMixIn(HashMap.class, HashMapMixin.class);

return objectMapper;
}

@Override
Expand Down