4444import org .springframework .security .jackson2 .SecurityJackson2Modules ;
4545import org .springframework .session .FindByIndexNameSessionRepository ;
4646import org .springframework .util .Assert ;
47+ import org .springframework .util .ClassUtils ;
4748
4849/**
4950 * {@code AbstractMongoSessionConverter} implementation using Jackson.
5051 *
5152 * @author Jakub Kubrynski
5253 * @author Greg Turnquist
5354 * @author Michael Ruf
55+ * @author TiQuan Hu
5456 * @since 1.2
5557 */
5658public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter {
@@ -93,9 +95,12 @@ protected Query getQueryForIndex(String indexName, Object indexValue) {
9395 }
9496
9597 private ObjectMapper buildObjectMapper () {
96-
9798 ObjectMapper objectMapper = new ObjectMapper ();
99+ configureObjectMapper (objectMapper );
100+ return objectMapper ;
101+ }
98102
103+ public static void configureObjectMapper (ObjectMapper objectMapper ) {
99104 // serialize fields instead of properties
100105 objectMapper .setVisibility (PropertyAccessor .ALL , JsonAutoDetect .Visibility .NONE );
101106 objectMapper .setVisibility (PropertyAccessor .FIELD , JsonAutoDetect .Visibility .ANY );
@@ -105,11 +110,9 @@ private ObjectMapper buildObjectMapper() {
105110
106111 objectMapper .setPropertyNamingStrategy (new MongoIdNamingStrategy ());
107112
108- objectMapper .registerModules (SecurityJackson2Modules .getModules (getClass (). getClassLoader ()));
113+ objectMapper .registerModules (SecurityJackson2Modules .getModules (ClassUtils . getDefaultClassLoader ()));
109114 objectMapper .addMixIn (MongoSession .class , MongoSessionMixin .class );
110115 objectMapper .addMixIn (HashMap .class , HashMapMixin .class );
111-
112- return objectMapper ;
113116 }
114117
115118 @ Override
0 commit comments