Browse Source

feat: change time serialize/deserialize pattern

master
vran 3 years ago
parent
commit
1bae49e2c4
  1. 16
      api/src/main/java/com/databasir/api/config/WebConfig.java

16
api/src/main/java/com/databasir/api/config/WebConfig.java

@ -1,10 +1,16 @@
package com.databasir.api.config;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.time.format.DateTimeFormatter;
@Configuration
@EnableSpringDataWebSupport
public class WebConfig extends WebMvcConfigurerAdapter {
@ -15,4 +21,14 @@ public class WebConfig extends WebMvcConfigurerAdapter {
.allowedOrigins("*")
.allowedMethods("GET", "POST", "DELETE", "PATCH", "PUT");
}
@Bean
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
final String dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
return builder -> {
builder.simpleDateFormat(dateTimeFormat);
builder.serializers(new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat)));
builder.deserializers(new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(dateTimeFormat)));
};
}
}
Loading…
Cancel
Save