|
|
@@ -1,15 +1,15 @@
|
|
1
|
1
|
package com.ruoyi.common.redis.configure;
|
|
2
|
2
|
|
|
3
|
|
-import com.alibaba.fastjson.JSON;
|
|
4
|
|
-import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
5
|
|
-import com.fasterxml.jackson.databind.JavaType;
|
|
6
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
7
|
|
-import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
|
3
|
+import java.nio.charset.Charset;
|
|
8
|
4
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
|
9
|
5
|
import org.springframework.data.redis.serializer.SerializationException;
|
|
10
|
|
-import com.alibaba.fastjson.parser.ParserConfig;
|
|
11
|
6
|
import org.springframework.util.Assert;
|
|
12
|
|
-import java.nio.charset.Charset;
|
|
|
7
|
+import com.alibaba.fastjson2.JSON;
|
|
|
8
|
+import com.alibaba.fastjson2.JSONReader;
|
|
|
9
|
+import com.alibaba.fastjson2.JSONWriter;
|
|
|
10
|
+import com.fasterxml.jackson.databind.JavaType;
|
|
|
11
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
12
|
+import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
13
|
13
|
|
|
14
|
14
|
/**
|
|
15
|
15
|
* Redis使用FastJson序列化
|
|
|
@@ -25,10 +25,6 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
|
25
|
25
|
|
|
26
|
26
|
private Class<T> clazz;
|
|
27
|
27
|
|
|
28
|
|
- static
|
|
29
|
|
- {
|
|
30
|
|
- ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
|
|
31
|
|
- }
|
|
32
|
28
|
|
|
33
|
29
|
public FastJson2JsonRedisSerializer(Class<T> clazz)
|
|
34
|
30
|
{
|
|
|
@@ -43,7 +39,7 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
|
43
|
39
|
{
|
|
44
|
40
|
return new byte[0];
|
|
45
|
41
|
}
|
|
46
|
|
- return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);
|
|
|
42
|
+ return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
|
|
47
|
43
|
}
|
|
48
|
44
|
|
|
49
|
45
|
@Override
|
|
|
@@ -55,7 +51,7 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
|
55
|
51
|
}
|
|
56
|
52
|
String str = new String(bytes, DEFAULT_CHARSET);
|
|
57
|
53
|
|
|
58
|
|
- return JSON.parseObject(str, clazz);
|
|
|
54
|
+ return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType);
|
|
59
|
55
|
}
|
|
60
|
56
|
|
|
61
|
57
|
public void setObjectMapper(ObjectMapper objectMapper)
|