import .;
import .;
import .;
import ;
import ;
import ;
import ;
import ;
import ;
public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
private Class<T> clazz;
public FastJsonRedisSerializer(Class<T> clazz) {
super();
= clazz;
}
//序列化
@Override
public byte[] serialize(T t) throws SerializationException {
if (t == null) {
return new byte[0];
}
return (t, ).getBytes(DEFAULT_CHARSET);
}
//反序列化
@Override
public T deserialize(byte[] bytes) throws SerializationException {
if (bytes == null || <= 0) {
return null;
}
String str = new String(bytes, DEFAULT_CHARSET);
return (str, clazz, );
}注意导包时import .;和import ;的区别。另一种解决方案见链接:fastjson2_autotype_cn · alibaba/fastjson2 Wiki · GitHub
相关文章
- FastJSON2反序列化报错:Resolved [: class cannot
- SpringBoot打jar包-下载文件时报错-class path resource xxxxxx cannot be resolved to URL because it does not exist
- eclipse中java文件报错:The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
- eclipse中java文件报错:The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files