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.
udi-spms-java/src/main/java/com/glxp/api/config/JacksonConfig.java

35 lines
1.4 KiB
Java

package com.glxp.api.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.glxp.api.config.serializer.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Configuration
public class JacksonConfig {
@Bean
@Primary
// @ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class, new LongJsonSerializer());
simpleModule.addDeserializer(Long.class, new LongJsonDeserializer());
simpleModule.addSerializer(LocalDate.class, new LocalDateJsonSerializer());
simpleModule.addDeserializer(LocalDate.class, new LocalDateJsonDeserializer());
simpleModule.addSerializer(LocalDateTime.class, new LocalDateTimeJsonSerializer());
simpleModule.addDeserializer(LocalDateTime.class, new LocalDateTimeJsonDeserializer());
objectMapper.registerModule(simpleModule);
return objectMapper;
}
}