mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-19 01:48:47 +08:00
Pre Merge pull request !699 from AprilWind/dev
This commit is contained in:
commit
83efefee94
@ -80,7 +80,7 @@ public class DefaultExcelListener<T> extends AnalysisEventListener<T> implements
|
||||
@Override
|
||||
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
|
||||
this.headMap = headMap;
|
||||
log.debug("解析到一条表头数据: {}", JsonUtils.toJsonString(headMap));
|
||||
log.debug("解析到一条表头数据: {}", JsonUtils.toSafeJsonString(headMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -111,7 +111,7 @@ public class RepeatSubmitAspect {
|
||||
}
|
||||
for (Object o : paramsArray) {
|
||||
if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
|
||||
params.add(JsonUtils.toJsonString(o));
|
||||
params.add(JsonUtils.toSafeJsonString(o));
|
||||
}
|
||||
}
|
||||
return params.toString();
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
package org.dromara.common.json.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
@ -47,4 +51,29 @@ public class JacksonConfig {
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("plusObjectMapper")
|
||||
public ObjectMapper plusObjectMapper() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addSerializer(Long.class, BigNumberSerializer.INSTANCE);
|
||||
javaTimeModule.addSerializer(Long.TYPE, BigNumberSerializer.INSTANCE);
|
||||
javaTimeModule.addSerializer(BigInteger.class, BigNumberSerializer.INSTANCE);
|
||||
javaTimeModule.addSerializer(BigDecimal.class, ToStringSerializer.instance);
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter));
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter));
|
||||
javaTimeModule.addDeserializer(Date.class, new CustomDateDeserializer());
|
||||
|
||||
mapper.registerModule(javaTimeModule);
|
||||
mapper.setTimeZone(TimeZone.getDefault());
|
||||
|
||||
log.info("初始化 plusObjectMapper 配置");
|
||||
return mapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,17 +25,20 @@ import java.util.List;
|
||||
public class JsonUtils {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = SpringUtils.getBean(ObjectMapper.class);
|
||||
private static final ObjectMapper PLUS_MAPPER = SpringUtils.getBean("plusObjectMapper", ObjectMapper.class);
|
||||
|
||||
public static ObjectMapper getObjectMapper() {
|
||||
return OBJECT_MAPPER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转换为JSON格式的字符串
|
||||
* 将对象转换为 JSON 字符串(使用全局增强版 ObjectMapper,包含字段翻译、脱敏等功能)
|
||||
* <p>
|
||||
* 注意:此方法会触发全局 BeanSerializerModifier,例如多语言翻译或字段脱敏
|
||||
* 建议仅用于实际响应数据或业务处理。
|
||||
*
|
||||
* @param object 要转换的对象
|
||||
* @return JSON格式的字符串,如果对象为null,则返回null
|
||||
* @throws RuntimeException 如果转换过程中发生JSON处理异常,则抛出运行时异常
|
||||
* @return JSON 字符串
|
||||
*/
|
||||
public static String toJsonString(Object object) {
|
||||
if (ObjectUtil.isNull(object)) {
|
||||
@ -48,6 +51,25 @@ public class JsonUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转换为 JSON 字符串(使用“纯净” ObjectMapper,不触发翻译、脱敏等增强逻辑)
|
||||
* <p>
|
||||
* 用于日志打印、幂等校验、缓存 Key 等场景,避免性能开销或逻辑副作用
|
||||
*
|
||||
* @param object 要转换的对象
|
||||
* @return JSON 字符串
|
||||
*/
|
||||
public static String toSafeJsonString(Object object) {
|
||||
if (ObjectUtil.isNull(object)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return PLUS_MAPPER.writeValueAsString(object);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将JSON格式的字符串转换为指定类型的对象
|
||||
*
|
||||
|
||||
@ -145,7 +145,7 @@ public class LogAspect {
|
||||
}
|
||||
// 是否需要保存response,参数和值
|
||||
if (log.isSaveResponseData() && ObjectUtil.isNotNull(jsonResult)) {
|
||||
operLog.setJsonResult(StringUtils.substring(JsonUtils.toJsonString(jsonResult), 0, 3800));
|
||||
operLog.setJsonResult(StringUtils.substring(JsonUtils.toSafeJsonString(jsonResult), 0, 3800));
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ public class LogAspect {
|
||||
} else {
|
||||
MapUtil.removeAny(paramsMap, EXCLUDE_PROPERTIES);
|
||||
MapUtil.removeAny(paramsMap, excludeParamNames);
|
||||
operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 3800));
|
||||
operLog.setOperParam(StringUtils.substring(JsonUtils.toSafeJsonString(paramsMap), 0, 3800));
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,12 +178,12 @@ public class LogAspect {
|
||||
}
|
||||
for (Object o : paramsArray) {
|
||||
if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
|
||||
String str = JsonUtils.toJsonString(o);
|
||||
String str = JsonUtils.toSafeJsonString(o);
|
||||
Dict dict = JsonUtils.parseMap(str);
|
||||
if (MapUtil.isNotEmpty(dict)) {
|
||||
MapUtil.removeAny(dict, EXCLUDE_PROPERTIES);
|
||||
MapUtil.removeAny(dict, excludeParamNames);
|
||||
str = JsonUtils.toJsonString(dict);
|
||||
str = JsonUtils.toSafeJsonString(dict);
|
||||
}
|
||||
params.add(str);
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class GlobalExceptionHandler {
|
||||
public String handleNotLoginException(SseException e, HttpServletRequest request) {
|
||||
String requestURI = request.getRequestURI();
|
||||
log.debug("请求地址'{}',认证失败'{}',无法访问系统资源", requestURI, e.getMessage());
|
||||
return JsonUtils.toJsonString(R.fail(HttpStatus.HTTP_UNAUTHORIZED, "认证失败,无法访问系统资源"));
|
||||
return JsonUtils.toSafeJsonString(R.fail(HttpStatus.HTTP_UNAUTHORIZED, "认证失败,无法访问系统资源"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -43,7 +43,7 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
||||
} else {
|
||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
if (MapUtil.isNotEmpty(parameterMap)) {
|
||||
String parameters = JsonUtils.toJsonString(parameterMap);
|
||||
String parameters = JsonUtils.toSafeJsonString(parameterMap);
|
||||
log.info("[PLUS]开始请求 => URL[{}],参数类型[param],参数:[{}]", url, parameters);
|
||||
} else {
|
||||
log.info("[PLUS]开始请求 => URL[{}],无参数", url);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user