From 6e8b8c086de2d100d5212f354dd70cc42b540b18 Mon Sep 17 00:00:00 2001 From: Adina Rolea Date: Wed, 4 Nov 2020 10:36:43 +0200 Subject: [PATCH] BAEL-4687: updated jackson configuration --- .../jackson/config/CoffeeConfiguration.java | 9 ++++++ .../config/CoffeeWebConfiguration.java | 32 ------------------- 2 files changed, 9 insertions(+), 32 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java index a6804a12f0..d13ce51e9b 100644 --- a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java +++ b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeConfiguration.java @@ -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) diff --git a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java b/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java deleted file mode 100644 index a53ab3a805..0000000000 --- a/spring-boot-modules/spring-boot-jackson/src/main/java/com/baeldung/boot/jackson/config/CoffeeWebConfiguration.java +++ /dev/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> converters) { - converters.add(mappingJackson2HttpMessageConverter()); - } - - @Bean - public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { - Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() - .serializers(localDateTimeSerializer) - .serializationInclusion(JsonInclude.Include.NON_NULL); - return new MappingJackson2HttpMessageConverter(builder.build()); - } -}