提交 2626e3d6 编写于 作者: zhouweidong's avatar zhouweidong

解决懒加载redis反序列化异常

上级 97212ad7
...@@ -13,6 +13,10 @@ public class CustomJacksonSerializer<T> extends Jackson2JsonRedisSerializer<T> ...@@ -13,6 +13,10 @@ public class CustomJacksonSerializer<T> extends Jackson2JsonRedisSerializer<T>
public static final String DEFAULT_PACKAGE ="[\\w+\\.]+\\.AuthenticationUser"; public static final String DEFAULT_PACKAGE ="[\\w+\\.]+\\.AuthenticationUser";
public static final String CLASSNAME_EX="_$$_";
public static final String CLASSNAME_EX_PATTEN="(_\\$\\$_)(\\w+)";
public static final String USER_PACKAGE= AuthenticationUser.class.getName(); public static final String USER_PACKAGE= AuthenticationUser.class.getName();
public CustomJacksonSerializer(Class type) { public CustomJacksonSerializer(Class type) {
...@@ -23,6 +27,12 @@ public class CustomJacksonSerializer<T> extends Jackson2JsonRedisSerializer<T> ...@@ -23,6 +27,12 @@ public class CustomJacksonSerializer<T> extends Jackson2JsonRedisSerializer<T>
public T deserialize(byte[] bytes) throws SerializationException { public T deserialize(byte[] bytes) throws SerializationException {
String serializerContent = new String(bytes, DEFAULT_CHARSET); String serializerContent = new String(bytes, DEFAULT_CHARSET);
Matcher matcher = Pattern.compile(DEFAULT_PACKAGE).matcher(serializerContent); Matcher matcher = Pattern.compile(DEFAULT_PACKAGE).matcher(serializerContent);
return matcher.find()?super.deserialize(serializerContent.replaceAll(DEFAULT_PACKAGE,USER_PACKAGE).getBytes()):super.deserialize(bytes); if(matcher.find()){
serializerContent=serializerContent.replaceAll(DEFAULT_PACKAGE,USER_PACKAGE);
}
if(serializerContent.contains(CLASSNAME_EX)){
serializerContent=serializerContent.replaceAll(CLASSNAME_EX_PATTEN,"");
}
return super.deserialize(serializerContent.getBytes());
} }
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册