-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f19e778
commit afd8239
Showing
2 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...-web/src/main/java/org/orcid/frontend/spring/configuration/OrcidBeanClassLoaderAware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.orcid.frontend.spring.configuration; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.beans.factory.BeanClassLoaderAware; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; | ||
import org.springframework.data.redis.serializer.RedisSerializer; | ||
import org.springframework.security.jackson2.SecurityJackson2Modules; | ||
|
||
@Configuration | ||
public class OrcidBeanClassLoaderAware implements BeanClassLoaderAware { | ||
private ClassLoader loader; | ||
|
||
@Bean | ||
public RedisSerializer<Object> springSessionDefaultRedisSerializer() { | ||
return new GenericJackson2JsonRedisSerializer(objectMapper()); | ||
} | ||
|
||
/** | ||
* Customized {@link ObjectMapper} to add mix-in for class that doesn't have default | ||
* constructors | ||
* @return the {@link ObjectMapper} to use | ||
*/ | ||
private ObjectMapper objectMapper() { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.registerModules(SecurityJackson2Modules.getModules(this.loader)); | ||
return mapper; | ||
} | ||
|
||
@Override | ||
public void setBeanClassLoader(ClassLoader classLoader) { | ||
this.loader = classLoader; | ||
} | ||
} |