title: Spring data redis override default serializer
body: <p>I am trying to create a <code>RedisTemplate</code> bean which will have the updated value serializer to serialize an object in <code>JSON</code> format in redis.</p>
  
  <pre><code>@Configuration
  class RedisConfig {
  
    @Bean(name = ["redisTemplate"])
    @Primary
    fun template(factory: RedisConnectionFactory): RedisTemplate&lt;Any, Any&gt; {
      val template = RedisTemplate&lt;Any, Any&gt;()
      template.connectionFactory = factory
      template.valueSerializer = Jackson2JsonRedisSerializer(Object::class.java)
      template.afterPropertiesSet()
      return template
    }
  }
  </code></pre>
  
  <p>As per my understanding, spring should use the JSON serializer to serialize the object returned by the methods marked with <code>Cacheable</code> annotation. Despite this configuration, spring seems to be using the default Java serializer as this exception confirms this fact.</p>
  
  <pre><code>java.io.NotSerializableException: en.prateekj.vds.dto.Task
  at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
  at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
  at java.util.ArrayList.writeObject(ArrayList.java:766)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1128)
  at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
  at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
  at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
  at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
  at org.springframework.core.serializer.DefaultSerializer.serialize(DefaultSerializer.java:46)
  at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:63)
  at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:35)
  at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.serialize(JdkSerializationRedisSerializer.java:94)
  at org.springframework.data.redis.serializer.DefaultRedisElementWriter.write(DefaultRedisElementWriter.java:43)
  at org.springframework.data.redis.serializer.RedisSerializationContext$SerializationPair.write(RedisSerializationContext.java:219)
  at org.springframework.data.redis.cache.RedisCache.serializeCacheValue(RedisCache.java:238)
  at org.springframework.data.redis.cache.RedisCache.put(RedisCache.java:144)
  at org.springframework.cache.interceptor.AbstractCacheInvoker.doPut(AbstractCacheInvoker.java:87)
  at org.springframework.cache.interceptor.CacheAspectSupport$CachePutRequest.apply(CacheAspectSupport.java:770)
  at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:398)
  at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:314)
  at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
  at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
  </code></pre>
  
  <p>Am I missing any configuration or something by which spring is not able to determine what <code>RedisTemplate</code> to use?</p>