Skip to content

Commit

Permalink
Expose configureObjectMapper as static.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoquanidea committed Sep 6, 2024
1 parent 0468697 commit 2ae93cb
Showing 1 changed file with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.security.jackson2.SecurityJackson2Modules;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -79,18 +80,6 @@ public JacksonMongoSessionConverter(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

public JacksonMongoSessionConverter(ObjectMapper objectMapper, boolean copyToUse) {
Assert.notNull(objectMapper, "ObjectMapper can not be null!");
if (!copyToUse) {
configureObjectMapper(objectMapper);
this.objectMapper = objectMapper;
return;
}
var objectMapperCopy = objectMapper.copy();
configureObjectMapper(objectMapperCopy);
this.objectMapper = objectMapperCopy;
}

@Nullable
protected Query getQueryForIndex(String indexName, Object indexValue) {

Expand All @@ -104,11 +93,11 @@ protected Query getQueryForIndex(String indexName, Object indexValue) {

private ObjectMapper buildObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
this.configureObjectMapper(objectMapper);
configureObjectMapper(objectMapper);
return objectMapper;
}

private void configureObjectMapper(ObjectMapper 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 @@ -118,7 +107,7 @@ private void configureObjectMapper(ObjectMapper objectMapper) {

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);
}
Expand Down

0 comments on commit 2ae93cb

Please sign in to comment.