From 8bdcc6e2780c08cf11b511320f126e669e7e231e Mon Sep 17 00:00:00 2001 From: xiwa Date: Tue, 10 Oct 2023 07:21:37 +0800 Subject: [PATCH] =?UTF-8?q?jsonUtils=E6=94=AF=E6=8C=81=E9=9D=9Espring?= =?UTF-8?q?=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iot-common-core/pom.xml | 1 - .../main/java/cc/iotkit/common/utils/JsonUtils.java | 11 ++++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/iot-common-core/pom.xml b/iot-common-core/pom.xml index 38d2d2d..d4bb49c 100755 --- a/iot-common-core/pom.xml +++ b/iot-common-core/pom.xml @@ -92,7 +92,6 @@ org.projectlombok lombok - provided diff --git a/iot-common-core/src/main/java/cc/iotkit/common/utils/JsonUtils.java b/iot-common-core/src/main/java/cc/iotkit/common/utils/JsonUtils.java index fe102af..244f5d6 100755 --- a/iot-common-core/src/main/java/cc/iotkit/common/utils/JsonUtils.java +++ b/iot-common-core/src/main/java/cc/iotkit/common/utils/JsonUtils.java @@ -1,5 +1,6 @@ package cc.iotkit.common.utils; +import cn.hutool.core.exceptions.UtilException; import cn.hutool.core.lang.Dict; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.PrimitiveArrayUtil; @@ -22,7 +23,15 @@ import java.util.Objects; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class JsonUtils { - private static final ObjectMapper OBJECT_MAPPER = SpringUtils.getBean(ObjectMapper.class); + private static ObjectMapper OBJECT_MAPPER; + + static { + try { + OBJECT_MAPPER = SpringUtils.getBean(ObjectMapper.class); + } catch (UtilException e) { + OBJECT_MAPPER = new ObjectMapper(); + } + } public static ObjectMapper getObjectMapper() { return OBJECT_MAPPER;