疯狂的狮子li
2022-09-02 17f0c20242c6ee3d35b9ee8f677d747ed012423c
ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java
@@ -1,6 +1,8 @@
package com.ruoyi.common.utils;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -11,7 +13,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * JSON 工具类
@@ -28,7 +29,7 @@
    }
    public static String toJsonString(Object object) {
        if (StringUtils.isNull(object)) {
        if (ObjectUtil.isNull(object)) {
            return null;
        }
        try {
@@ -71,13 +72,23 @@
        }
    }
    public static <T> Map<String, T> parseMap(String text) {
    public static Dict parseMap(String text) {
        if (StringUtils.isBlank(text)) {
            return null;
        }
        try {
            return OBJECT_MAPPER.readValue(text, new TypeReference<Map<String, T>>() {
            });
            return OBJECT_MAPPER.readValue(text, OBJECT_MAPPER.getTypeFactory().constructType(Dict.class));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static List<Dict> parseArrayMap(String text) {
        if (StringUtils.isBlank(text)) {
            return null;
        }
        try {
            return OBJECT_MAPPER.readValue(text, OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, Dict.class));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }