perf:移除hutool-json,直接使用fastjson

This commit is contained in:
曾文豪
2024-08-23 15:04:20 +08:00
parent 9bab4cdb25
commit 4bcae2f8d1
23 changed files with 176 additions and 116 deletions

View File

@@ -4,10 +4,8 @@ package com.tiesheng.util;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
public class CharacterUtils {
@@ -24,19 +22,24 @@ public class CharacterUtils {
/**
* 移除特殊字符
*
* @param o 类
* @param o
* @param searchStr 规则
*/
public static void removeSymbol(Object o, String searchStr) {
JSONObject object = JSONUtil.parseObj(o, false);
for (Map.Entry<String, Object> entry : object) {
if (ObjectUtil.isEmpty(entry.getValue()) || StrUtil.equals("null", String.valueOf(entry.getValue()))) {
entry.setValue("");
JSONObject object = JSON.parseObject(JSON.toJSONString(o));
for (String key : object.keySet()) {
if (StrUtil.isEmpty(key)) {
continue;
}
if (StrUtil.isNotEmpty(entry.getKey())) {
entry.setValue(StrUtil.trim(StrUtil.replace(entry.getValue().toString(), searchStr, "")));
Object value = object.get(key);
if (ObjectUtil.isEmpty(value) || StrUtil.equals("null", String.valueOf(value))) {
object.put(key, "");
continue;
}
String replace = StrUtil.replace(String.valueOf(value), searchStr, "");
object.put(key, StrUtil.trim(replace));
}
BeanUtil.copyProperties(object, o);
}

View File

@@ -3,7 +3,7 @@ package com.tiesheng.util.service;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.tiesheng.util.ServletKit;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.service.cache.TsCacheHandler;
@@ -36,7 +36,7 @@ public class TsCacheService {
}
public void putObj(String key, Object value, long seconds) {
tsCacheHandler.put(key, JSONUtil.toJsonStr(value), seconds);
tsCacheHandler.put(key, JSON.toJSONString(value), seconds);
}
public String get(String key) {
@@ -58,7 +58,7 @@ public class TsCacheService {
* @return
*/
public <T> T getObj(String key, Class<T> tClass, long seconds) {
return JSONUtil.toBean(get(key, seconds), tClass, true);
return JSON.parseObject(get(key, seconds), tClass);
}
public void remove(String key) {

View File

@@ -4,7 +4,7 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.net.url.UrlQuery;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import java.io.File;