package com.bowintek.practice.config; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.TimeZone; @Configuration @Slf4j public class JsonObjectMapperConfig { @Bean //@Primary public ObjectMapper ObjectMapper(){ log.info("配置 -> jackson-datatype-jsr310--注册"); ObjectMapper objectMapper = new ObjectMapper(); var javaTimeModule=new JavaTimeModule(); //javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ISO_DATE_TIME)); objectMapper.registerModule(javaTimeModule); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.setTimeZone(TimeZone.getDefault()); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; } }