update 更新 jackson 配置 支持 LocalDateTime 全局格式化

This commit is contained in:
疯狂的狮子li
2021-09-07 13:18:36 +08:00
parent 38f03855eb
commit c5d46591fe
2 changed files with 25 additions and 38 deletions

View File

@ -4,6 +4,9 @@ import cn.hutool.core.util.ArrayUtil;
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;
@ -15,20 +18,10 @@ import java.util.Map;
*
* @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 (StringUtils.isNull(object)) {