疯狂的狮子li
2021-10-15 a6fb88d74c20cc28043d75e8a5097fce49cf9a78
ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java
@@ -1,11 +1,12 @@
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;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.utils.spring.SpringUtils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.io.IOException;
import java.util.ArrayList;
@@ -17,23 +18,13 @@
 *
 * @author 芋道源码
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class JsonUtils {
    private static ObjectMapper objectMapper = new ObjectMapper();
    /**
     * 初始化 objectMapper 属性
     * <p>
     * 通过这样的方式,使用 Spring 创建的 ObjectMapper Bean
     *
     * @param objectMapper ObjectMapper 对象
     */
    public static void init(ObjectMapper objectMapper) {
        JsonUtils.objectMapper = objectMapper;
    }
    private static ObjectMapper objectMapper = SpringUtils.getBean(ObjectMapper.class);
    public static String toJsonString(Object object) {
      if (Validator.isEmpty(object)) {
      if (StringUtils.isNull(object)) {
         return null;
      }
        try {
@@ -44,7 +35,7 @@
    }
    public static <T> T parseObject(String text, Class<T> clazz) {
        if (StrUtil.isEmpty(text)) {
        if (StringUtils.isEmpty(text)) {
            return null;
        }
        try {
@@ -66,7 +57,7 @@
    }
    public static <T> T parseObject(String text, TypeReference<T> typeReference) {
      if (StrUtil.isBlank(text)) {
      if (StringUtils.isBlank(text)) {
         return null;
      }
        try {
@@ -77,7 +68,7 @@
    }
   public static <T> Map<String, T> parseMap(String text) {
      if (StrUtil.isBlank(text)) {
      if (StringUtils.isBlank(text)) {
         return null;
      }
      try {
@@ -88,7 +79,7 @@
   }
    public static <T> List<T> parseArray(String text, Class<T> clazz) {
        if (StrUtil.isEmpty(text)) {
        if (StringUtils.isEmpty(text)) {
            return new ArrayList<>();
        }
        try {