redis 反序列化出错 :SerializationFailedException: Failed to deserialize payload

错误信息:

[ERROR] 2018-03-07 14:05:03,747 XXX - Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.StreamCorruptedException: invalid stream header: 6E756C6C

解决方案:

添加反序列化配置.

@Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        final RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        redisTemplate.setKeySerializer(new KeyRedisSerializer());
        redisTemplate.setValueSerializer(new FastJsonRedisValueSerializer(HibernateLazyLoadingFilter.getInstance()));
        return redisTemplate;

    }

序列化处理:

   

 public byte[] serialize(Object t) throws SerializationException {
        if(t == null) {
            return null;
        }
        
        return JSONObject.toJSONString(t, propertyFilter, SerializerFeature.WriteClassName).getBytes(IOUtils.UTF8);

    }

反序列化处理:

public T deserialize(byte[] bytes) throws SerializationException {
        if(bytes == null) {
            return null;
        }
        
        return (T)JSONObject.parse(bytes);
    }


  

你可能感兴趣的:(Redis,restful学习)