mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 02:08:43 +08:00 
			
		
		
		
	update 优化 jackson 自动配置 改为使用 BeanPostProcessor 匿名处理
This commit is contained in:
		| @@ -5,17 +5,27 @@ import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeSerializer; | |||||||
| import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||||||
| import com.fasterxml.jackson.databind.ObjectMapper; | import com.fasterxml.jackson.databind.ObjectMapper; | ||||||
| import com.fasterxml.jackson.databind.module.SimpleModule; | import com.fasterxml.jackson.databind.module.SimpleModule; | ||||||
|  | import lombok.extern.slf4j.Slf4j; | ||||||
|  | import org.springframework.beans.BeansException; | ||||||
|  | import org.springframework.beans.factory.config.BeanPostProcessor; | ||||||
| import org.springframework.context.annotation.Bean; | import org.springframework.context.annotation.Bean; | ||||||
| import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||||
|  |  | ||||||
| import java.time.LocalDateTime; | import java.time.LocalDateTime; | ||||||
|  |  | ||||||
|  | @Slf4j | ||||||
| @Configuration | @Configuration | ||||||
| public class YudaoJacksonAutoConfiguration { | public class YudaoJacksonAutoConfiguration { | ||||||
|  |  | ||||||
|     @Bean |     @Bean | ||||||
|     @SuppressWarnings("InstantiationOfUtilityClass") |     public BeanPostProcessor objectMapperBeanPostProcessor() { | ||||||
|     public JsonUtils jsonUtils(ObjectMapper objectMapper) { |         return new BeanPostProcessor() { | ||||||
|  |             @Override | ||||||
|  |             public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | ||||||
|  |                 if (!(bean instanceof ObjectMapper)) { | ||||||
|  |                     return bean; | ||||||
|  |                 } | ||||||
|  |                 ObjectMapper objectMapper = (ObjectMapper) bean; | ||||||
|                 SimpleModule simpleModule = new SimpleModule(); |                 SimpleModule simpleModule = new SimpleModule(); | ||||||
|                 /* |                 /* | ||||||
|                  * 1. 新增Long类型序列化规则,数值超过2^53-1,在JS会出现精度丢失问题,因此Long自动序列化为字符串类型 |                  * 1. 新增Long类型序列化规则,数值超过2^53-1,在JS会出现精度丢失问题,因此Long自动序列化为字符串类型 | ||||||
| @@ -30,6 +40,10 @@ public class YudaoJacksonAutoConfiguration { | |||||||
|                 objectMapper.registerModules(simpleModule); |                 objectMapper.registerModules(simpleModule); | ||||||
|  |  | ||||||
|                 JsonUtils.init(objectMapper); |                 JsonUtils.init(objectMapper); | ||||||
|         return new JsonUtils(); |                 log.info("初始化 jackson 自动配置"); | ||||||
|  |                 return bean; | ||||||
|             } |             } | ||||||
|  |         }; | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 疯狂的狮子li
					疯狂的狮子li