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