44
44
import org .springframework .security .jackson2 .SecurityJackson2Modules ;
45
45
import org .springframework .session .FindByIndexNameSessionRepository ;
46
46
import org .springframework .util .Assert ;
47
+ import org .springframework .util .ClassUtils ;
47
48
48
49
/**
49
50
* {@code AbstractMongoSessionConverter} implementation using Jackson.
50
51
*
51
52
* @author Jakub Kubrynski
52
53
* @author Greg Turnquist
53
54
* @author Michael Ruf
55
+ * @author TiQuan Hu
54
56
* @since 1.2
55
57
*/
56
58
public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter {
@@ -93,9 +95,12 @@ protected Query getQueryForIndex(String indexName, Object indexValue) {
93
95
}
94
96
95
97
private ObjectMapper buildObjectMapper () {
96
-
97
98
ObjectMapper objectMapper = new ObjectMapper ();
99
+ configureObjectMapper (objectMapper );
100
+ return objectMapper ;
101
+ }
98
102
103
+ public static void configureObjectMapper (ObjectMapper objectMapper ) {
99
104
// serialize fields instead of properties
100
105
objectMapper .setVisibility (PropertyAccessor .ALL , JsonAutoDetect .Visibility .NONE );
101
106
objectMapper .setVisibility (PropertyAccessor .FIELD , JsonAutoDetect .Visibility .ANY );
@@ -105,11 +110,9 @@ private ObjectMapper buildObjectMapper() {
105
110
106
111
objectMapper .setPropertyNamingStrategy (new MongoIdNamingStrategy ());
107
112
108
- objectMapper .registerModules (SecurityJackson2Modules .getModules (getClass (). getClassLoader ()));
113
+ objectMapper .registerModules (SecurityJackson2Modules .getModules (ClassUtils . getDefaultClassLoader ()));
109
114
objectMapper .addMixIn (MongoSession .class , MongoSessionMixin .class );
110
115
objectMapper .addMixIn (HashMap .class , HashMapMixin .class );
111
-
112
- return objectMapper ;
113
116
}
114
117
115
118
@ Override
0 commit comments