From 099e745b8f9c7ae7747407c75ec6cd2582cc5e06 Mon Sep 17 00:00:00 2001 From: JEECG <445654970@qq.com> Date: Wed, 24 Jul 2024 20:03:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E5=8E=9Fjackson=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?online=E7=9A=84=E5=B8=A6=E6=97=B6=E9=97=B4=E7=9A=84=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E5=80=BC=E9=83=BD=E5=B8=A6T?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/config/WebMvcConfiguration.java | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java index 26f7053b..060a66df 100644 --- a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java +++ b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java @@ -12,18 +12,14 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; import io.micrometer.prometheus.PrometheusMeterRegistry; import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; -import org.springframework.boot.autoconfigure.jackson.JacksonProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; @@ -40,7 +36,6 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.List; -import java.util.Objects; /** * Spring Boot 2.0 解决跨域问题 @@ -59,11 +54,6 @@ public class WebMvcConfiguration implements WebMvcConfigurer { @Autowired(required = false) private PrometheusMeterRegistry prometheusMeterRegistry; - @Autowired - private ObjectProvider builderProvider; - @Autowired - private JacksonProperties jacksonProperties; - /** * 静态资源的配置 - 使得可以从磁盘中读取 Html、图片、视频、音频等 */ @@ -116,10 +106,6 @@ public class WebMvcConfiguration implements WebMvcConfigurer { @Primary public ObjectMapper objectMapper() { ObjectMapper objectMapper = new ObjectMapper(); - // 继承spring jackson 默认机制 - if (Objects.nonNull(builderProvider.getIfAvailable())) { - objectMapper = builderProvider.getIfAvailable().createXmlMapper(false).build(); - } //处理bigDecimal objectMapper.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN); objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); @@ -128,10 +114,8 @@ public class WebMvcConfiguration implements WebMvcConfigurer { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false); objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, false); - //默认的处理日期时间格式,接受通过spring.jackson.date-format配置格式化模式 - if (Objects.isNull(jacksonProperties.getDateFormat())) { - objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); - } + //默认的处理日期时间格式 + objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); JavaTimeModule javaTimeModule = new JavaTimeModule(); javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));