Przeglądaj źródła

升级fastjson到最新版2.0.4

RuoYi 3 lat temu
rodzic
commit
cdcc466300

+ 3 - 3
pom.xml

@@ -33,7 +33,7 @@
33 33
         <commons.io.version>2.11.0</commons.io.version>
34 34
         <commons.fileupload.version>1.4</commons.fileupload.version>
35 35
         <velocity.version>2.3</velocity.version>
36
-        <fastjson.version>1.2.83</fastjson.version>
36
+        <fastjson.version>2.0.4</fastjson.version>
37 37
         <jjwt.version>0.9.1</jjwt.version>
38 38
         <minio.version>8.2.2</minio.version>
39 39
         <poi.version>4.1.2</poi.version>
@@ -163,8 +163,8 @@
163 163
 
164 164
             <!-- JSON 解析器和生成器 -->
165 165
             <dependency>
166
-                <groupId>com.alibaba</groupId>
167
-                <artifactId>fastjson</artifactId>
166
+                <groupId>com.alibaba.fastjson2</groupId>
167
+                <artifactId>fastjson2</artifactId>
168 168
                 <version>${fastjson.version}</version>
169 169
             </dependency>
170 170
 

+ 2 - 2
ruoyi-common/ruoyi-common-core/pom.xml

@@ -67,8 +67,8 @@
67 67
 
68 68
         <!-- Alibaba Fastjson -->
69 69
         <dependency>
70
-            <groupId>com.alibaba</groupId>
71
-            <artifactId>fastjson</artifactId>
70
+            <groupId>com.alibaba.fastjson2</groupId>
71
+            <artifactId>fastjson2</artifactId>
72 72
         </dependency>
73 73
 
74 74
         <!-- Jwt -->

+ 2 - 2
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java

@@ -18,7 +18,7 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
18 18
 import org.springframework.web.context.request.RequestAttributes;
19 19
 import org.springframework.web.context.request.RequestContextHolder;
20 20
 import org.springframework.web.context.request.ServletRequestAttributes;
21
-import com.alibaba.fastjson.JSONObject;
21
+import com.alibaba.fastjson2.JSON;
22 22
 import com.ruoyi.common.core.constant.Constants;
23 23
 import com.ruoyi.common.core.domain.R;
24 24
 import com.ruoyi.common.core.text.Convert;
@@ -296,7 +296,7 @@ public class ServletUtils
296 296
         response.setStatusCode(status);
297 297
         response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType);
298 298
         R<?> result = R.fail(code, value.toString());
299
-        DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONString(result).getBytes());
299
+        DataBuffer dataBuffer = response.bufferFactory().wrap(JSON.toJSONString(result).getBytes());
300 300
         return response.writeWith(Mono.just(dataBuffer));
301 301
     }
302 302
 }

+ 1 - 1
ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java

@@ -15,7 +15,7 @@ import org.springframework.http.HttpMethod;
15 15
 import org.springframework.stereotype.Component;
16 16
 import org.springframework.validation.BindingResult;
17 17
 import org.springframework.web.multipart.MultipartFile;
18
-import com.alibaba.fastjson.JSON;
18
+import com.alibaba.fastjson2.JSON;
19 19
 import com.ruoyi.common.core.utils.ServletUtils;
20 20
 import com.ruoyi.common.core.utils.StringUtils;
21 21
 import com.ruoyi.common.core.utils.ip.IpUtils;

+ 9 - 13
ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/configure/FastJson2JsonRedisSerializer.java

@@ -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)

+ 3 - 2
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/ValidateCodeFilter.java

@@ -10,7 +10,8 @@ import org.springframework.core.io.buffer.DataBuffer;
10 10
 import org.springframework.core.io.buffer.DataBufferUtils;
11 11
 import org.springframework.http.server.reactive.ServerHttpRequest;
12 12
 import org.springframework.stereotype.Component;
13
-import com.alibaba.fastjson.JSONObject;
13
+import com.alibaba.fastjson2.JSON;
14
+import com.alibaba.fastjson2.JSONObject;
14 15
 import com.ruoyi.common.core.utils.ServletUtils;
15 16
 import com.ruoyi.common.core.utils.StringUtils;
16 17
 import com.ruoyi.gateway.config.properties.CaptchaProperties;
@@ -52,7 +53,7 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object>
52 53
             try
53 54
             {
54 55
                 String rspStr = resolveBodyFromRequest(request);
55
-                JSONObject obj = JSONObject.parseObject(rspStr);
56
+                JSONObject obj = JSON.parseObject(rspStr);
56 57
                 validateCodeService.checkCaptcha(obj.getString(CODE), obj.getString(UUID));
57 58
             }
58 59
             catch (Exception e)

+ 4 - 4
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java

@@ -21,8 +21,8 @@ import org.slf4j.LoggerFactory;
21 21
 import org.springframework.beans.factory.annotation.Autowired;
22 22
 import org.springframework.stereotype.Service;
23 23
 import org.springframework.transaction.annotation.Transactional;
24
-import com.alibaba.fastjson.JSON;
25
-import com.alibaba.fastjson.JSONObject;
24
+import com.alibaba.fastjson2.JSON;
25
+import com.alibaba.fastjson2.JSONObject;
26 26
 import com.ruoyi.common.core.constant.Constants;
27 27
 import com.ruoyi.common.core.constant.GenConstants;
28 28
 import com.ruoyi.common.core.exception.ServiceException;
@@ -401,7 +401,7 @@ public class GenTableServiceImpl implements IGenTableService
401 401
         if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
402 402
         {
403 403
             String options = JSON.toJSONString(genTable.getParams());
404
-            JSONObject paramsObj = JSONObject.parseObject(options);
404
+            JSONObject paramsObj = JSON.parseObject(options);
405 405
             if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
406 406
             {
407 407
                 throw new ServiceException("树编码字段不能为空");
@@ -485,7 +485,7 @@ public class GenTableServiceImpl implements IGenTableService
485 485
      */
486 486
     public void setTableFromOptions(GenTable genTable)
487 487
     {
488
-        JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions());
488
+        JSONObject paramsObj = JSON.parseObject(genTable.getOptions());
489 489
         if (StringUtils.isNotNull(paramsObj))
490 490
         {
491 491
             String treeCode = paramsObj.getString(GenConstants.TREE_CODE);

+ 5 - 4
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java

@@ -5,7 +5,8 @@ import java.util.HashSet;
5 5
 import java.util.List;
6 6
 import java.util.Set;
7 7
 import org.apache.velocity.VelocityContext;
8
-import com.alibaba.fastjson.JSONObject;
8
+import com.alibaba.fastjson2.JSON;
9
+import com.alibaba.fastjson2.JSONObject;
9 10
 import com.ruoyi.common.core.constant.GenConstants;
10 11
 import com.ruoyi.common.core.utils.DateUtils;
11 12
 import com.ruoyi.common.core.utils.StringUtils;
@@ -75,7 +76,7 @@ public class VelocityUtils
75 76
     public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
76 77
     {
77 78
         String options = genTable.getOptions();
78
-        JSONObject paramsObj = JSONObject.parseObject(options);
79
+        JSONObject paramsObj = JSON.parseObject(options);
79 80
         String parentMenuId = getParentMenuId(paramsObj);
80 81
         context.put("parentMenuId", parentMenuId);
81 82
     }
@@ -83,7 +84,7 @@ public class VelocityUtils
83 84
     public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
84 85
     {
85 86
         String options = genTable.getOptions();
86
-        JSONObject paramsObj = JSONObject.parseObject(options);
87
+        JSONObject paramsObj = JSON.parseObject(options);
87 88
         String treeCode = getTreecode(paramsObj);
88 89
         String treeParentCode = getTreeParentCode(paramsObj);
89 90
         String treeName = getTreeName(paramsObj);
@@ -381,7 +382,7 @@ public class VelocityUtils
381 382
     public static int getExpandColumn(GenTable genTable)
382 383
     {
383 384
         String options = genTable.getOptions();
384
-        JSONObject paramsObj = JSONObject.parseObject(options);
385
+        JSONObject paramsObj = JSON.parseObject(options);
385 386
         String treeName = paramsObj.getString(GenConstants.TREE_NAME);
386 387
         int num = 0;
387 388
         for (GenTableColumn column : genTable.getColumns())