38
38
import org .springframework .security .jackson2 .SecurityJackson2Modules ;
39
39
import org .springframework .session .FindByIndexNameSessionRepository ;
40
40
import org .springframework .util .Assert ;
41
+ import org .springframework .util .ClassUtils ;
41
42
42
43
import java .io .IOException ;
43
44
import java .util .Collections ;
@@ -79,18 +80,6 @@ public JacksonMongoSessionConverter(ObjectMapper objectMapper) {
79
80
this .objectMapper = objectMapper ;
80
81
}
81
82
82
- public JacksonMongoSessionConverter (ObjectMapper objectMapper , boolean copyToUse ) {
83
- Assert .notNull (objectMapper , "ObjectMapper can not be null!" );
84
- if (!copyToUse ) {
85
- configureObjectMapper (objectMapper );
86
- this .objectMapper = objectMapper ;
87
- return ;
88
- }
89
- var objectMapperCopy = objectMapper .copy ();
90
- configureObjectMapper (objectMapperCopy );
91
- this .objectMapper = objectMapperCopy ;
92
- }
93
-
94
83
@ Nullable
95
84
protected Query getQueryForIndex (String indexName , Object indexValue ) {
96
85
@@ -104,11 +93,11 @@ protected Query getQueryForIndex(String indexName, Object indexValue) {
104
93
105
94
private ObjectMapper buildObjectMapper () {
106
95
ObjectMapper objectMapper = new ObjectMapper ();
107
- this . configureObjectMapper (objectMapper );
96
+ configureObjectMapper (objectMapper );
108
97
return objectMapper ;
109
98
}
110
99
111
- private void configureObjectMapper (ObjectMapper objectMapper ) {
100
+ public static void configureObjectMapper (ObjectMapper objectMapper ) {
112
101
// serialize fields instead of properties
113
102
objectMapper .setVisibility (PropertyAccessor .ALL , JsonAutoDetect .Visibility .NONE );
114
103
objectMapper .setVisibility (PropertyAccessor .FIELD , JsonAutoDetect .Visibility .ANY );
@@ -118,7 +107,7 @@ private void configureObjectMapper(ObjectMapper objectMapper) {
118
107
119
108
objectMapper .setPropertyNamingStrategy (new MongoIdNamingStrategy ());
120
109
121
- objectMapper .registerModules (SecurityJackson2Modules .getModules (getClass (). getClassLoader ()));
110
+ objectMapper .registerModules (SecurityJackson2Modules .getModules (ClassUtils . getDefaultClassLoader ()));
122
111
objectMapper .addMixIn (MongoSession .class , MongoSessionMixin .class );
123
112
objectMapper .addMixIn (HashMap .class , HashMapMixin .class );
124
113
}
0 commit comments