fix 修复 JsonUtils 参数为空报错

This commit is contained in:
疯狂的狮子li
2021-06-16 13:15:18 +08:00
parent 639816369a
commit 2cdc12055d
3 changed files with 22 additions and 11 deletions

View File

@ -1,5 +1,6 @@
package com.ruoyi.common.utils;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
@ -32,6 +33,9 @@ public class JsonUtils {
}
public static String toJsonString(Object object) {
if (Validator.isEmpty(object)) {
return null;
}
try {
return objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
@ -62,6 +66,9 @@ public class JsonUtils {
}
public static <T> T parseObject(String text, TypeReference<T> typeReference) {
if (StrUtil.isBlank(text)) {
return null;
}
try {
return objectMapper.readValue(text, typeReference);
} catch (IOException e) {
@ -70,6 +77,9 @@ public class JsonUtils {
}
public static <T> Map<String, T> parseMap(String text) {
if (StrUtil.isBlank(text)) {
return null;
}
try {
return objectMapper.readValue(text, new TypeReference<Map<String, T>>() {});
} catch (IOException e) {