How to deserialize an object stored in redis, if the classname of the stored object changes?

Abhishek :

I have stored an object in redis, say Class StorageConnection,

public void storeSecureConnection(String uniqueKey, Object storageConnection) {
        redisTemplateAdmin.opsForValue().set(uniqueKey, storageConnection);

}

Now, I have changed the className from StorageConnection to DataConnection. All the fields and UID remains intact.

It's now giving me an SerializationException on

public DataConnection getAdminDataObject(String uniqueKey) {    
        return  (DataConnection) redisTemplateAdmin.opsForValue().get(uniqueKey);
    }

Is there any trick that I can deserialize it with new className?

Edit:

Here's RedisTemplate Initialization:

@Service
public class AdminDataBaseServiceImpl{
    private RedisTemplate<String, Object> redisTemplateAdmin;
    private HashOperations hashOps;

    private AdminDataBaseServiceImpl(RedisTemplate<String, Object> redisTemplateAdmin) {
    this.redisTemplateAdmin = redisTemplateAdmin;
    hashOps=redisTemplateAdmin.opsForHash();
}
Abhishek :

I used GenericJackson2JsonRedisSerializer to serialize the object and was storing in redis. To change the class name, I used StringRedisSerializer to deserialize, changed the classname and again stored in Redis with StringRedisSerializer.

Then used, as usual, GenericJackson2JsonRedisSerializer to deserialize the object with new classname. It worked.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=106049&siteId=1