fix(#758): DictUtils 移除 fastjson2,统一使用 jackson
- com.alibaba.fastjson2.JSONArray → jackson ObjectMapper - com.alibaba.fastjson2.JSON.toJSONString/parseObject → mapper.writeValueAsString/readValue - 项目统一使用 jackson,不再依赖 fastjson2
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.core.common.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.core.common.constant.CacheConstants;
|
||||
import com.core.common.core.domain.entity.SysDictData;
|
||||
import com.core.common.core.redis.RedisCache;
|
||||
@@ -46,19 +47,17 @@ public class DictUtils {
|
||||
if (cached == null) {
|
||||
return null;
|
||||
}
|
||||
if (cached instanceof JSONArray arrayCache) {
|
||||
return arrayCache.toList(SysDictData.class);
|
||||
}
|
||||
if (cached instanceof List<?> list) {
|
||||
// Redis缓存可能已反序列化为List,尝试逐个转换
|
||||
java.util.ArrayList<SysDictData> result = new java.util.ArrayList<>(list.size());
|
||||
ObjectMapper mapper = SpringUtils.getBean(ObjectMapper.class);
|
||||
for (Object item : list) {
|
||||
if (item instanceof SysDictData dictData) {
|
||||
result.add(dictData);
|
||||
} else {
|
||||
// 尝试通过JSON转换
|
||||
String json = com.alibaba.fastjson2.JSON.toJSONString(item);
|
||||
result.add(com.alibaba.fastjson2.JSON.parseObject(json, SysDictData.class));
|
||||
// 通过 Jackson JSON 转换
|
||||
String json = mapper.writeValueAsString(item);
|
||||
result.add(mapper.readValue(json, SysDictData.class));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user