Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Error handling in deserialisation in redis CacheManager in springboot

$
0
0

I am trying to use cutom serialisation for redis CacheManager in spring boot instead of using default java serialisation. How do I do error handling here? If there is a serialisation/deserialisation error, I want to delete the key from redis or atleast add a log line. Please find my implementation of custom serialisation using jackson

@BeanRedisCacheManager redisCacheManager(RedisConnectionFactory factory) {    StringRedisSerializer stringSerializer = new StringRedisSerializer();    ObjectMapper mapper = new ObjectMapper();    PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder()            .allowIfSubType("com.example")            .allowIfSubType("java.sql.Timestamp")            .allowIfSubType("org.hibernate.collection")            .allowIfSubType("java.util.List")            .allowIfSubType("java.util.ArrayList")            .build();    mapper.activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);    RedisSerializer jacksonSerializer = new GenericJackson2JsonRedisSerializer(mapper);    return new RedisCacheManager(            RedisCacheWriter.nonLockingRedisCacheWriter(factory),            RedisCacheConfiguration.defaultCacheConfig()                    .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(stringSerializer))                    .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jacksonSerializer))    );}

Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>