BAEL-4687: updated jackson configuration
This commit is contained in:
parent
0218395e89
commit
6e8b8c086d
|
@ -10,6 +10,7 @@ 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 org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
|
@ -18,6 +19,14 @@ public class CoffeeConfiguration {
|
|||
public static final String dateTimeFormat = "dd-MM-yyyy HH:mm";
|
||||
private LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat));
|
||||
|
||||
@Bean
|
||||
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
|
||||
.serializers(localDateTimeSerializer)
|
||||
.serializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
return new MappingJackson2HttpMessageConverter(builder.build());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
|
||||
return builder -> builder.serializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
package com.baeldung.boot.jackson.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class CoffeeWebConfiguration implements WebMvcConfigurer {
|
||||
public static final String dateTimeFormat = "dd-MM-yyyy HH:mm";
|
||||
private LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat));
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(mappingJackson2HttpMessageConverter());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
|
||||
.serializers(localDateTimeSerializer)
|
||||
.serializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
return new MappingJackson2HttpMessageConverter(builder.build());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue