title: Redis: class java.lang.String cannot be cast to class java.util.List in @Cacheable method
body: <p>I need to add a Redis cache in a method that returns a list of values.</p>
  
  <p>I'm using this tutorial as basis <a href="https://www.baeldung.com/spring-data-redis-tutorial" rel="nofollow noreferrer">https://www.baeldung.com/spring-data-redis-tutorial</a></p>
  
  <p>The exception shows this</p>
  
  <pre><code>java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.List (java.lang.String and java.util.List are in module java.base of loader 'bootstrap')
      at 
  
  @Cacheable(cacheNames = "customerDetailByParam", key="{#searchParams.toString()}")
      @Retryable(value = { HttpServerErrorException.class }, maxAttempts =  RETRY_ATTEMPTS, backoff = @Backoff(delay = 5000))
      public List&lt;ObjectResponse&gt; searchCustomerDetailByParam(MultiValueMap&lt;String, String&gt; searchParams) 
  </code></pre>
  
  <p>I've been looking for some solutions, however, none seems to work.</p>
  
  <p>CacheConfig.java</p>
  
  <pre><code>@Configuration
  @EnableCaching
  @ConditionalOnMissingBean(value = CacheManager.class)
  @Slf4j
  public class CacheConfig {
  
      @Bean
      JedisConnectionFactory jedisConnectionFactory() {
          RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6379);
          //redisStandaloneConfiguration.setPassword(RedisPassword.of("yourRedisPasswordIfAny"));
          return new JedisConnectionFactory(redisStandaloneConfiguration);
      }
  
      @Bean
      public RedisTemplate&lt;String, Object&gt; redisTemplate() {
          final RedisTemplate&lt;String, Object&gt; template = new RedisTemplate&lt;String, Object&gt;();
          template.setConnectionFactory(jedisConnectionFactory());
          template.setValueSerializer(new GenericToStringSerializer&lt;Object&gt;(Object.class));
          template.setHashValueSerializer(new Jackson2JsonRedisSerializer&lt;&gt;(Object.class));
          RedisSerializer&lt;Object&gt; serializer = new JdkSerializationRedisSerializer(getClass().getClassLoader());
  
          template.setDefaultSerializer(serializer);
  
          return template;
      }
  
  
  }
  </code></pre>
  
  <p>ObjectResponse.java</p>
  
  <pre><code>@Data
  @NoArgsConstructor
  @AllArgsConstructor
  public class ObjectResponse implements Serializable {
  
      @JsonProperty("id")
      private String customerId;
  
      @JsonProperty("name")
      @JsonAlias("full_name")
      private String customerName;
  
      private String document;
  
      private String email;
  
  }
  </code></pre>