package com.mingzuozhibi.commons.gson;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.time.*;
import java.time.format.DateTimeFormatter;

@Configuration
public class JacksonConfig {

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer customJackson() {
        return builder -> {
            builder.serializationInclusion(Include.NON_NULL);
            builder.modulesToInstall(getSimpleModule());
        };
    }

    private SimpleModule getSimpleModule() {
        SimpleModule module = new SimpleModule();
        module.addSerializer(Instant.class, new JsonSerializer<Instant>() {
            public void serialize(Instant value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
                gen.writeNumber(value.toEpochMilli());
            }
        });
        module.addDeserializer(Instant.class, new JsonDeserializer<Instant>() {
            public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
                return Instant.ofEpochMilli(p.getLongValue());
            }
        });
        module.addSerializer(LocalDateTime.class, new JsonSerializer<LocalDateTime>() {
            public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
                gen.writeNumber(value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
            }
        });
        module.addDeserializer(LocalDateTime.class, new JsonDeserializer<LocalDateTime>() {
            public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
                return Instant.ofEpochMilli(p.getLongValue()).atZone(ZoneId.systemDefault()).toLocalDateTime();
            }
        });
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/M/d");
        module.addSerializer(LocalDate.class, new JsonSerializer<LocalDate>() {
            public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
                gen.writeString(value.format(formatter));
            }
        });
        module.addDeserializer(LocalDate.class, new JsonDeserializer<LocalDate>() {
            public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
                return LocalDate.parse(p.getText(), formatter);
            }
        });
        return module;
    }

}

@@ -128,17 +128,75 @@
 on.core.
-*
+JsonGenerator;%0Aimport com.fasterxml.jackson.core.JsonParser
 ;%0Aimport
@@ -548,49 +548,133 @@
 .*;%0A
+%0A
 import 
-java.time.format.DateTimeFormatter
+static com.mingzuozhibi.commons.utils.FormatUtils.fmtDate;%0Aimport static com.mingzuozhibi.commons.utils.MyTimeUtils.*
 ;%0A%0A@
@@ -900,36 +900,34 @@
     
-builder.modulesToInstall(get
+SimpleModule module = new 
 Simp
@@ -936,18 +936,18 @@
 Module()
-)
 ;
+%0A
 %0A       
@@ -951,110 +951,71 @@
     
-%7D;%0A
     
-%7D%0A%0A    private SimpleModule getSimpleModule() %7B%0A        SimpleModule module = new SimpleM
+withLocalDateTime(module);%0A            withLocalDate(m
 odule
-(
 );%0A 
@@ -1025,256 +1025,80 @@
     
+ 
-module.addSerializer(Instant.class, new JsonSerializer%3CInstant%3E() %7B%0A            public void serialize(Instant value, JsonGenerator gen, SerializerProvider serializers) throws IOException %7B%0A                gen.writeNumber(value.toEpochMilli());%0A    
+   withInsatnt(module);%0A%0A            builder.modulesToInstall(module);%0A
     
@@ -1106,310 +1106,74 @@
    %7D
+;
 %0A
-    
     %7D
-);
+%0A
 %0A    
-    module.addDeserializer(Instant.class, new JsonDeserializer%3CInstant%3E() %7B%0A            public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException %7B%0A                return Instant.ofEpochMilli(p.getLongValue());%0A            %7D%0A        %7D);
+private void withLocalDateTime(SimpleModule module) %7B
 %0A   
@@ -1420,57 +1420,8 @@
 ber(
-value.atZone(ZoneId.systemDefault()).toInstant().
 toEp
@@ -1429,16 +1429,21 @@
 chMilli(
+value
 ));%0A    
@@ -1662,34 +1662,16 @@
 xception
-, JacksonException
  %7B%0A     
@@ -1692,16 +1692,8 @@
 urn 
-Instant.
 ofEp
@@ -1722,57 +1722,8 @@
 e())
-.atZone(ZoneId.systemDefault()).toLocalDateTime()
 ;%0A  
@@ -1754,82 +1754,64 @@
     
+%7D%0A%0A
     
-DateTimeFormatter formatter = DateTimeFormatter.ofPattern(%22yyyy/M/d%22);
+private void withLocalDate(SimpleModule module) %7B
 %0A   
@@ -2056,24 +2056,22 @@
 format(f
-ormat
+mtDa
 te
-r
 ));%0A    
@@ -2282,26 +2282,8 @@
 tion
-, JacksonException
  %7B%0A 
@@ -2338,66 +2338,650 @@
 ), f
-ormatter);%0A            %7D%0A        %7D);%0A        return module
+mtDate);%0A            %7D%0A        %7D);%0A    %7D%0A%0A    private void withInsatnt(SimpleModule module) %7B%0A        module.addSerializer(Instant.class, new JsonSerializer%3CInstant%3E() %7B%0A            public void serialize(Instant value, JsonGenerator gen, SerializerProvider serializers) throws IOException %7B%0A                gen.writeNumber(value.toEpochMilli());%0A            %7D%0A        %7D);%0A        module.addDeserializer(Instant.class, new JsonDeserializer%3CInstant%3E() %7B%0A            public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException %7B%0A                return Instant.ofEpochMilli(p.getLongValue());%0A            %7D%0A        %7D)
 ;%0A  

update jackson config