For example, I have a serialized value like below stored as string in Redis, which represents a list of UserAction objects:
["java.util.ArrayList",[{"@class":"com.domain.UserAction","id":1,"name":"Login"},{"@class":"com.domain.UserAction","id":2,"name":"Logout"}]]
when I tried to access this via its key (e.g.UserActionsCache
) via redisTemplate:
RedisTemplate<String, UserAction> redisTemplate;redisTemplate.opsForValue().get(key);
it throws an error like:
org.springframework.data.redis.serializer.SerializationException: Could not read JSON:Could not resolve type id `com.domain.UserAction` as a subtype of `java.lang.Object`: no such class found
i tried changing the redisTemplate
to below, but it has the same issue:
RedisTemplate<String, List<UserAction>> redisTemplate;RedisTemplate<String, ArrayList<UserAction>> redisTemplate;RedisTemplate<String, Object> redisTemplate;
How do you properly access the value and deserialize it to a list of objects?
P.S. This is part of my redisTemplate config:
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisConnFactory" p:keySerializer-ref="stringRedisSerializer" p:valueSerializer-ref="genericJackson2JsonRedisSerializer" p:hashKeySerializer-ref="stringRedisSerializer" p:hashValueSerializer-ref="genericJackson2JsonRedisSerializer" />