redis修正
This commit is contained in:
@@ -37,9 +37,15 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
||||
{
|
||||
return new byte[0];
|
||||
}
|
||||
// 对String类型直接返回原始字节,不做JSON序列化
|
||||
if (t instanceof String)
|
||||
{
|
||||
return ((String) t).getBytes(DEFAULT_CHARSET);
|
||||
}
|
||||
return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T deserialize(byte[] bytes) throws SerializationException
|
||||
{
|
||||
@@ -48,7 +54,15 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
||||
return null;
|
||||
}
|
||||
String str = new String(bytes, DEFAULT_CHARSET);
|
||||
|
||||
// 对String类型直接返回字符串
|
||||
if (clazz == String.class || clazz == Object.class && !str.startsWith("{") && !str.startsWith("["))
|
||||
{
|
||||
// 如果是纯字符串(非JSON格式),直接返回
|
||||
if (!str.startsWith("\"") && !str.startsWith("{") && !str.startsWith("["))
|
||||
{
|
||||
return (T) str;
|
||||
}
|
||||
}
|
||||
return JSON.parseObject(str, clazz, AUTO_TYPE_FILTER);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user