2026-07-01 6b5f7c66fc40d7f6099d561e31a34fbd50dd20d3
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/JsonUtils.java
@@ -22,6 +22,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * JSON 工具类
@@ -36,13 +37,12 @@
    private static ObjectMapper buildObjectMapper() {
        SimpleModule simpleModule = new SimpleModule()
                // 解决 LocalDateTime 的序列化
                .addSerializer(LocalDateTime.class, TimestampLocalDateTimeSerializer.INSTANCE)
                .addDeserializer(LocalDateTime.class, TimestampLocalDateTimeDeserializer.INSTANCE);
        return JsonMapper.builder()
                .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                // 强制将整数反序列化为 Long,解决 Redis 缓存反序列化时 Integer 转 Long 的问题
                .enable(DeserializationFeature.USE_LONG_FOR_INTS)
                .changeDefaultPropertyInclusion(value -> JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL))
                .addModule(simpleModule)
                .build();
@@ -177,6 +177,23 @@
    }
    /**
     * 解析 JSON 字符串成 Map,空字符串或解析失败返回 null
     *
     * @param text JSON 字符串
     * @return Map 对象
     */
    public static Map<String, Object> parseMap(String text) {
        if (StrUtil.isEmpty(text)) {
            return null;
        }
        try {
            return objectMapper.readValue(text, new TypeReference<Map<String, Object>>() {});
        } catch (JacksonException e) {
            return null;
        }
    }
    /**
     * 解析 JSON 字符串成指定类型的对象,如果解析失败,则返回 null
     *
     * @param text 字符串
@@ -238,6 +255,14 @@
        }
    }
    public static String getText(JsonNode node, String fieldName) {
        if (node == null) {
            return null;
        }
        JsonNode value = node.get(fieldName);
        return value != null && !value.isNull() ? value.asText() : null;
    }
    public static boolean isJson(String text) {
        return JSONUtil.isTypeJSON(text);
    }