From 2455d0b859708e39fa9fd5b710bebee45c32b085 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 15 十二月 2021 15:03:44 +0800 Subject: [PATCH] add 增加 自定义 Xss 校验注解 用户导入增加 Bean 校验 --- ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java index b65c23d..1c01912 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java @@ -21,14 +21,18 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class JsonUtils { - private static ObjectMapper objectMapper = SpringUtils.getBean(ObjectMapper.class); + private static final ObjectMapper OBJECT_MAPPER = SpringUtils.getBean(ObjectMapper.class); + + public static ObjectMapper getObjectMapper() { + return OBJECT_MAPPER; + } public static String toJsonString(Object object) { if (StringUtils.isNull(object)) { return null; } try { - return objectMapper.writeValueAsString(object); + return OBJECT_MAPPER.writeValueAsString(object); } catch (JsonProcessingException e) { throw new RuntimeException(e); } @@ -39,7 +43,7 @@ return null; } try { - return objectMapper.readValue(text, clazz); + return OBJECT_MAPPER.readValue(text, clazz); } catch (IOException e) { throw new RuntimeException(e); } @@ -50,7 +54,7 @@ return null; } try { - return objectMapper.readValue(bytes, clazz); + return OBJECT_MAPPER.readValue(bytes, clazz); } catch (IOException e) { throw new RuntimeException(e); } @@ -61,7 +65,7 @@ return null; } try { - return objectMapper.readValue(text, typeReference); + return OBJECT_MAPPER.readValue(text, typeReference); } catch (IOException e) { throw new RuntimeException(e); } @@ -72,7 +76,7 @@ return null; } try { - return objectMapper.readValue(text, new TypeReference<Map<String, T>>() { + return OBJECT_MAPPER.readValue(text, new TypeReference<Map<String, T>>() { }); } catch (IOException e) { throw new RuntimeException(e); @@ -84,7 +88,7 @@ return new ArrayList<>(); } try { - return objectMapper.readValue(text, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); + return OBJECT_MAPPER.readValue(text, OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, clazz)); } catch (IOException e) { throw new RuntimeException(e); } -- Gitblit v1.9.3