Skip to content

Commit

Permalink
chore: redis 관련 기능들만 커스텀 objectMapper 사용하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekks committed Dec 12, 2024
1 parent f8b966c commit a6219e2
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,16 @@ public RedisConnectionFactory redisConnectionFactory() {
}

@Bean
public ObjectMapper objectMapper() {
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // ISO-8601 형식
objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(),
ObjectMapper.DefaultTyping.NON_FINAL); // 타입 정보 추가

return objectMapper;
}

@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory,
ObjectMapper objectMapper) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);

StringRedisSerializer stringSerializer = new StringRedisSerializer();
GenericJackson2JsonRedisSerializer jsonSerializer = new GenericJackson2JsonRedisSerializer(objectMapper);

Expand All @@ -66,8 +60,14 @@ public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisC
}

@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory, ObjectMapper objectMapper) {
public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
// 동일한 직렬화 설정 공유
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // ISO-8601 형식
objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(),
ObjectMapper.DefaultTyping.NON_FINAL); // 타입 정보 추가

GenericJackson2JsonRedisSerializer jsonSerializer = new GenericJackson2JsonRedisSerializer(objectMapper);

RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig()
Expand Down

0 comments on commit a6219e2

Please sign in to comment.