org.springframework.data.redis.serializer.JdkSerializationRedisSerializer序列化工具
2017-05-28 01:18
525 查看
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
/**
* 序列化工具类
*/
public class SerializerUtil {
private static final JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer();
/**
* 序列化对象
*
* @param obj
* @return
*/
public static <T> byte[] serialize(T obj) {
try {
return jdkSerializationRedisSerializer.serialize(obj);
} catch (Exception e) {
throw new RuntimeException("序列化失败!", e);
}
}
/**
* 反序列化对象
*
* @param bytes 字节数组
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T deserialize(byte[] bytes) {
try {
return (T) jdkSerializationRedisSerializer.deserialize(bytes);
} catch (Exception e) {
throw new RuntimeException("反序列化失败!", e);
}
}
}
/**
* 序列化工具类
*/
public class SerializerUtil {
private static final JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer();
/**
* 序列化对象
*
* @param obj
* @return
*/
public static <T> byte[] serialize(T obj) {
try {
return jdkSerializationRedisSerializer.serialize(obj);
} catch (Exception e) {
throw new RuntimeException("序列化失败!", e);
}
}
/**
* 反序列化对象
*
* @param bytes 字节数组
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T deserialize(byte[] bytes) {
try {
return (T) jdkSerializationRedisSerializer.deserialize(bytes);
} catch (Exception e) {
throw new RuntimeException("反序列化失败!", e);
}
}
}
相关文章推荐
- org.springframework.data.redis.serializer.SerializationException: Cannot serialize;
- Source Taste: Spring Data: Redis: JdkSerializationRedisSerializer
- spring data redis serializer SerializationException 序列化问题
- Spring源码追踪1——doGetBean(为什么org.springframework.data.redis.core.RedisTemplate的实例可以注入为ListOperations)
- Spring源码追踪1——doGetBean(为什么org.springframework.data.redis.core.RedisTemplate的实例可以注入为ListOperations)
- spring-data-redis使用jdk序列化时increment的异常
- org.springframework.data.redis.RedisSystemException: Unknown redis exception; nested exception is ja
- spring data redis rg.springframework.core.serializer.support.DeserializingConverter.<init>(Ljava/lan
- org.springframework.data.redis.RedisSystemException: Unknown redis exception; nested exception is ja
- spring-data-redis 整合,以及使用kryo序列化代替jdk原生序列化机制
- Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFai
- org.springframework.data.redis.RedisConnectionFailureException
- spring+redis 报错 org.springframework.core.serializer.support.DeserializingConverter.<init>(Ljava/lang/ClassLoader;)V
- Spring源码追踪1——doGetBean(为什么org.springframework.data.redis.core.RedisTemplate的实例可以注入为ListOperations)
- org.springframework.dao.InvalidDataAccessResourceUsageException: could not insert:
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read
- 关于Spring Data redis几种对象序列化的比较
- org.springframework.dao.InvalidDataAccessApiUsageException
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode