jsonUtils支持非spring环境

master
xiwa 2023-10-10 07:21:37 +08:00
parent 8233338198
commit 8bdcc6e278
2 changed files with 10 additions and 2 deletions

View File

@ -92,7 +92,6 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -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;