作者 RuoYi

升级fastjson到最新版2.0.4

@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 <kaptcha.version>2.3.2</kaptcha.version> 24 <kaptcha.version>2.3.2</kaptcha.version>
25 <mybatis-spring-boot.version>2.2.2</mybatis-spring-boot.version> 25 <mybatis-spring-boot.version>2.2.2</mybatis-spring-boot.version>
26 <pagehelper.boot.version>1.4.1</pagehelper.boot.version> 26 <pagehelper.boot.version>1.4.1</pagehelper.boot.version>
27 - <fastjson.version>1.2.83</fastjson.version> 27 + <fastjson.version>2.0.4</fastjson.version>
28 <oshi.version>6.1.6</oshi.version> 28 <oshi.version>6.1.6</oshi.version>
29 <commons.io.version>2.11.0</commons.io.version> 29 <commons.io.version>2.11.0</commons.io.version>
30 <commons.fileupload.version>1.4</commons.fileupload.version> 30 <commons.fileupload.version>1.4</commons.fileupload.version>
@@ -132,8 +132,8 @@ @@ -132,8 +132,8 @@
132 132
133 <!-- 阿里JSON解析器 --> 133 <!-- 阿里JSON解析器 -->
134 <dependency> 134 <dependency>
135 - <groupId>com.alibaba</groupId>  
136 - <artifactId>fastjson</artifactId> 135 + <groupId>com.alibaba.fastjson2</groupId>
  136 + <artifactId>fastjson2</artifactId>
137 <version>${fastjson.version}</version> 137 <version>${fastjson.version}</version>
138 </dependency> 138 </dependency>
139 139
@@ -61,8 +61,8 @@ @@ -61,8 +61,8 @@
61 61
62 <!-- 阿里JSON解析器 --> 62 <!-- 阿里JSON解析器 -->
63 <dependency> 63 <dependency>
64 - <groupId>com.alibaba</groupId>  
65 - <artifactId>fastjson</artifactId> 64 + <groupId>com.alibaba.fastjson2</groupId>
  65 + <artifactId>fastjson2</artifactId>
66 </dependency> 66 </dependency>
67 67
68 <!-- io常用工具类 --> 68 <!-- io常用工具类 -->
@@ -4,7 +4,7 @@ import java.util.Collection; @@ -4,7 +4,7 @@ import java.util.Collection;
4 import java.util.Set; 4 import java.util.Set;
5 import org.springframework.security.core.GrantedAuthority; 5 import org.springframework.security.core.GrantedAuthority;
6 import org.springframework.security.core.userdetails.UserDetails; 6 import org.springframework.security.core.userdetails.UserDetails;
7 -import com.alibaba.fastjson.annotation.JSONField; 7 +import com.alibaba.fastjson2.annotation.JSONField;
8 import com.ruoyi.common.core.domain.entity.SysUser; 8 import com.ruoyi.common.core.domain.entity.SysUser;
9 9
10 /** 10 /**
@@ -18,7 +18,7 @@ public class InvalidExtensionException extends FileUploadException @@ -18,7 +18,7 @@ public class InvalidExtensionException extends FileUploadException
18 18
19 public InvalidExtensionException(String[] allowedExtension, String extension, String filename) 19 public InvalidExtensionException(String[] allowedExtension, String extension, String filename)
20 { 20 {
21 - super("文件[" + filename + "]后缀[" + extension + "]不正确,请上传 [" + Arrays.toString(allowedExtension) + "]格式文件"); 21 + super("文件[" + filename + "]后缀[" + extension + "]不正确,请上传" + Arrays.toString(allowedExtension) + "格式");
22 this.allowedExtension = allowedExtension; 22 this.allowedExtension = allowedExtension;
23 this.extension = extension; 23 this.extension = extension;
24 this.filename = filename; 24 this.filename = filename;
@@ -2,7 +2,8 @@ package com.ruoyi.common.utils.ip; @@ -2,7 +2,8 @@ package com.ruoyi.common.utils.ip;
2 2
3 import org.slf4j.Logger; 3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 4 import org.slf4j.LoggerFactory;
5 -import com.alibaba.fastjson.JSONObject; 5 +import com.alibaba.fastjson2.JSON;
  6 +import com.alibaba.fastjson2.JSONObject;
6 import com.ruoyi.common.config.RuoYiConfig; 7 import com.ruoyi.common.config.RuoYiConfig;
7 import com.ruoyi.common.constant.Constants; 8 import com.ruoyi.common.constant.Constants;
8 import com.ruoyi.common.utils.StringUtils; 9 import com.ruoyi.common.utils.StringUtils;
@@ -40,7 +41,7 @@ public class AddressUtils @@ -40,7 +41,7 @@ public class AddressUtils
40 log.error("获取地理位置异常 {}", ip); 41 log.error("获取地理位置异常 {}", ip);
41 return UNKNOWN; 42 return UNKNOWN;
42 } 43 }
43 - JSONObject obj = JSONObject.parseObject(rspStr); 44 + JSONObject obj = JSON.parseObject(rspStr);
44 String region = obj.getString("pro"); 45 String region = obj.getString("pro");
45 String city = obj.getString("city"); 46 String city = obj.getString("city");
46 return String.format("%s %s", region, city); 47 return String.format("%s %s", region, city);
@@ -14,7 +14,7 @@ import org.springframework.stereotype.Component; @@ -14,7 +14,7 @@ import org.springframework.stereotype.Component;
14 import org.springframework.validation.BindingResult; 14 import org.springframework.validation.BindingResult;
15 import org.springframework.web.multipart.MultipartFile; 15 import org.springframework.web.multipart.MultipartFile;
16 import org.springframework.web.servlet.HandlerMapping; 16 import org.springframework.web.servlet.HandlerMapping;
17 -import com.alibaba.fastjson.JSON; 17 +import com.alibaba.fastjson2.JSON;
18 import com.ruoyi.common.annotation.Log; 18 import com.ruoyi.common.annotation.Log;
19 import com.ruoyi.common.core.domain.model.LoginUser; 19 import com.ruoyi.common.core.domain.model.LoginUser;
20 import com.ruoyi.common.enums.BusinessStatus; 20 import com.ruoyi.common.enums.BusinessStatus;
1 package com.ruoyi.framework.config; 1 package com.ruoyi.framework.config;
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 import org.springframework.data.redis.serializer.RedisSerializer; 4 import org.springframework.data.redis.serializer.RedisSerializer;
9 import org.springframework.data.redis.serializer.SerializationException; 5 import org.springframework.data.redis.serializer.SerializationException;
10 -import com.alibaba.fastjson.parser.ParserConfig;  
11 import org.springframework.util.Assert; 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 * Redis使用FastJson序列化 15 * Redis使用FastJson序列化
@@ -25,11 +25,6 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> @@ -25,11 +25,6 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
25 25
26 private Class<T> clazz; 26 private Class<T> clazz;
27 27
28 - static  
29 - {  
30 - ParserConfig.getGlobalInstance().setAutoTypeSupport(true);  
31 - }  
32 -  
33 public FastJson2JsonRedisSerializer(Class<T> clazz) 28 public FastJson2JsonRedisSerializer(Class<T> clazz)
34 { 29 {
35 super(); 30 super();
@@ -43,7 +38,7 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> @@ -43,7 +38,7 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
43 { 38 {
44 return new byte[0]; 39 return new byte[0];
45 } 40 }
46 - return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET); 41 + return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
47 } 42 }
48 43
49 @Override 44 @Override
@@ -55,7 +50,7 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> @@ -55,7 +50,7 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
55 } 50 }
56 String str = new String(bytes, DEFAULT_CHARSET); 51 String str = new String(bytes, DEFAULT_CHARSET);
57 52
58 - return JSON.parseObject(str, clazz); 53 + return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType);
59 } 54 }
60 55
61 public void setObjectMapper(ObjectMapper objectMapper) 56 public void setObjectMapper(ObjectMapper objectMapper)
@@ -6,7 +6,7 @@ import javax.servlet.http.HttpServletResponse; @@ -6,7 +6,7 @@ import javax.servlet.http.HttpServletResponse;
6 import org.springframework.stereotype.Component; 6 import org.springframework.stereotype.Component;
7 import org.springframework.web.method.HandlerMethod; 7 import org.springframework.web.method.HandlerMethod;
8 import org.springframework.web.servlet.HandlerInterceptor; 8 import org.springframework.web.servlet.HandlerInterceptor;
9 -import com.alibaba.fastjson.JSONObject; 9 +import com.alibaba.fastjson2.JSON;
10 import com.ruoyi.common.annotation.RepeatSubmit; 10 import com.ruoyi.common.annotation.RepeatSubmit;
11 import com.ruoyi.common.core.domain.AjaxResult; 11 import com.ruoyi.common.core.domain.AjaxResult;
12 import com.ruoyi.common.utils.ServletUtils; 12 import com.ruoyi.common.utils.ServletUtils;
@@ -32,7 +32,7 @@ public abstract class RepeatSubmitInterceptor implements HandlerInterceptor @@ -32,7 +32,7 @@ public abstract class RepeatSubmitInterceptor implements HandlerInterceptor
32 if (this.isRepeatSubmit(request, annotation)) 32 if (this.isRepeatSubmit(request, annotation))
33 { 33 {
34 AjaxResult ajaxResult = AjaxResult.error(annotation.message()); 34 AjaxResult ajaxResult = AjaxResult.error(annotation.message());
35 - ServletUtils.renderString(response, JSONObject.toJSONString(ajaxResult)); 35 + ServletUtils.renderString(response, JSON.toJSONString(ajaxResult));
36 return false; 36 return false;
37 } 37 }
38 } 38 }
@@ -7,7 +7,7 @@ import javax.servlet.http.HttpServletRequest; @@ -7,7 +7,7 @@ import javax.servlet.http.HttpServletRequest;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.beans.factory.annotation.Value; 8 import org.springframework.beans.factory.annotation.Value;
9 import org.springframework.stereotype.Component; 9 import org.springframework.stereotype.Component;
10 -import com.alibaba.fastjson.JSONObject; 10 +import com.alibaba.fastjson2.JSON;
11 import com.ruoyi.common.annotation.RepeatSubmit; 11 import com.ruoyi.common.annotation.RepeatSubmit;
12 import com.ruoyi.common.constant.Constants; 12 import com.ruoyi.common.constant.Constants;
13 import com.ruoyi.common.core.redis.RedisCache; 13 import com.ruoyi.common.core.redis.RedisCache;
@@ -50,7 +50,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor @@ -50,7 +50,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
50 // body参数为空,获取Parameter的数据 50 // body参数为空,获取Parameter的数据
51 if (StringUtils.isEmpty(nowParams)) 51 if (StringUtils.isEmpty(nowParams))
52 { 52 {
53 - nowParams = JSONObject.toJSONString(request.getParameterMap()); 53 + nowParams = JSON.toJSONString(request.getParameterMap());
54 } 54 }
55 Map<String, Object> nowDataMap = new HashMap<String, Object>(); 55 Map<String, Object> nowDataMap = new HashMap<String, Object>();
56 nowDataMap.put(REPEAT_PARAMS, nowParams); 56 nowDataMap.put(REPEAT_PARAMS, nowParams);
@@ -7,7 +7,7 @@ import javax.servlet.http.HttpServletResponse; @@ -7,7 +7,7 @@ import javax.servlet.http.HttpServletResponse;
7 import org.springframework.security.core.AuthenticationException; 7 import org.springframework.security.core.AuthenticationException;
8 import org.springframework.security.web.AuthenticationEntryPoint; 8 import org.springframework.security.web.AuthenticationEntryPoint;
9 import org.springframework.stereotype.Component; 9 import org.springframework.stereotype.Component;
10 -import com.alibaba.fastjson.JSON; 10 +import com.alibaba.fastjson2.JSON;
11 import com.ruoyi.common.constant.HttpStatus; 11 import com.ruoyi.common.constant.HttpStatus;
12 import com.ruoyi.common.core.domain.AjaxResult; 12 import com.ruoyi.common.core.domain.AjaxResult;
13 import com.ruoyi.common.utils.ServletUtils; 13 import com.ruoyi.common.utils.ServletUtils;
@@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.context.annotation.Configuration; 8 import org.springframework.context.annotation.Configuration;
9 import org.springframework.security.core.Authentication; 9 import org.springframework.security.core.Authentication;
10 import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; 10 import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
11 -import com.alibaba.fastjson.JSON; 11 +import com.alibaba.fastjson2.JSON;
12 import com.ruoyi.common.constant.Constants; 12 import com.ruoyi.common.constant.Constants;
13 import com.ruoyi.common.constant.HttpStatus; 13 import com.ruoyi.common.constant.HttpStatus;
14 import com.ruoyi.common.core.domain.AjaxResult; 14 import com.ruoyi.common.core.domain.AjaxResult;
@@ -21,8 +21,8 @@ import org.slf4j.LoggerFactory; @@ -21,8 +21,8 @@ import org.slf4j.LoggerFactory;
21 import org.springframework.beans.factory.annotation.Autowired; 21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.stereotype.Service; 22 import org.springframework.stereotype.Service;
23 import org.springframework.transaction.annotation.Transactional; 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 import com.ruoyi.common.constant.Constants; 26 import com.ruoyi.common.constant.Constants;
27 import com.ruoyi.common.constant.GenConstants; 27 import com.ruoyi.common.constant.GenConstants;
28 import com.ruoyi.common.core.text.CharsetKit; 28 import com.ruoyi.common.core.text.CharsetKit;
@@ -401,7 +401,7 @@ public class GenTableServiceImpl implements IGenTableService @@ -401,7 +401,7 @@ public class GenTableServiceImpl implements IGenTableService
401 if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) 401 if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
402 { 402 {
403 String options = JSON.toJSONString(genTable.getParams()); 403 String options = JSON.toJSONString(genTable.getParams());
404 - JSONObject paramsObj = JSONObject.parseObject(options); 404 + JSONObject paramsObj = JSON.parseObject(options);
405 if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) 405 if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
406 { 406 {
407 throw new ServiceException("树编码字段不能为空"); 407 throw new ServiceException("树编码字段不能为空");
@@ -485,7 +485,7 @@ public class GenTableServiceImpl implements IGenTableService @@ -485,7 +485,7 @@ public class GenTableServiceImpl implements IGenTableService
485 */ 485 */
486 public void setTableFromOptions(GenTable genTable) 486 public void setTableFromOptions(GenTable genTable)
487 { 487 {
488 - JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions()); 488 + JSONObject paramsObj = JSON.parseObject(genTable.getOptions());
489 if (StringUtils.isNotNull(paramsObj)) 489 if (StringUtils.isNotNull(paramsObj))
490 { 490 {
491 String treeCode = paramsObj.getString(GenConstants.TREE_CODE); 491 String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
@@ -5,7 +5,8 @@ import java.util.HashSet; @@ -5,7 +5,8 @@ import java.util.HashSet;
5 import java.util.List; 5 import java.util.List;
6 import java.util.Set; 6 import java.util.Set;
7 import org.apache.velocity.VelocityContext; 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 import com.ruoyi.common.constant.GenConstants; 10 import com.ruoyi.common.constant.GenConstants;
10 import com.ruoyi.common.utils.DateUtils; 11 import com.ruoyi.common.utils.DateUtils;
11 import com.ruoyi.common.utils.StringUtils; 12 import com.ruoyi.common.utils.StringUtils;
@@ -75,7 +76,7 @@ public class VelocityUtils @@ -75,7 +76,7 @@ public class VelocityUtils
75 public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) 76 public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
76 { 77 {
77 String options = genTable.getOptions(); 78 String options = genTable.getOptions();
78 - JSONObject paramsObj = JSONObject.parseObject(options); 79 + JSONObject paramsObj = JSON.parseObject(options);
79 String parentMenuId = getParentMenuId(paramsObj); 80 String parentMenuId = getParentMenuId(paramsObj);
80 context.put("parentMenuId", parentMenuId); 81 context.put("parentMenuId", parentMenuId);
81 } 82 }
@@ -83,7 +84,7 @@ public class VelocityUtils @@ -83,7 +84,7 @@ public class VelocityUtils
83 public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) 84 public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
84 { 85 {
85 String options = genTable.getOptions(); 86 String options = genTable.getOptions();
86 - JSONObject paramsObj = JSONObject.parseObject(options); 87 + JSONObject paramsObj = JSON.parseObject(options);
87 String treeCode = getTreecode(paramsObj); 88 String treeCode = getTreecode(paramsObj);
88 String treeParentCode = getTreeParentCode(paramsObj); 89 String treeParentCode = getTreeParentCode(paramsObj);
89 String treeName = getTreeName(paramsObj); 90 String treeName = getTreeName(paramsObj);
@@ -381,7 +382,7 @@ public class VelocityUtils @@ -381,7 +382,7 @@ public class VelocityUtils
381 public static int getExpandColumn(GenTable genTable) 382 public static int getExpandColumn(GenTable genTable)
382 { 383 {
383 String options = genTable.getOptions(); 384 String options = genTable.getOptions();
384 - JSONObject paramsObj = JSONObject.parseObject(options); 385 + JSONObject paramsObj = JSON.parseObject(options);
385 String treeName = paramsObj.getString(GenConstants.TREE_NAME); 386 String treeName = paramsObj.getString(GenConstants.TREE_NAME);
386 int num = 0; 387 int num = 0;
387 for (GenTableColumn column : genTable.getColumns()) 388 for (GenTableColumn column : genTable.getColumns())