You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.6 KiB
Java
37 lines
1.6 KiB
Java
1 year ago
|
package com.supervision.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.deser.LocalDateTimeDeserializer;
|
||
|
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||
|
import org.springframework.context.annotation.Bean;
|
||
|
import org.springframework.context.annotation.Configuration;
|
||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||
|
|
||
|
import java.time.LocalDateTime;
|
||
|
import java.time.format.DateTimeFormatter;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
@Configuration
|
||
|
public class WebConfig implements WebMvcConfigurer {
|
||
|
|
||
|
@Bean
|
||
|
public ObjectMapper objectMapper() {
|
||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||
|
|
||
|
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||
|
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||
|
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||
|
|
||
|
objectMapper.registerModule(javaTimeModule);
|
||
|
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||
|
|
||
|
return objectMapper;
|
||
|
}
|
||
|
}
|