From 2dee73ce1f6889365721d717acdd4641b3f34e13 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 5 Dec 2023 12:52:59 +0200 Subject: [PATCH] support iso dates --- .../main/java/eu/eudat/EuDatApplication.java | 23 +++++-------------- .../configurations/WebMVCConfiguration.java | 6 +++++ .../src/main/resources/config/application.yml | 4 ++++ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/EuDatApplication.java b/dmp-backend/web/src/main/java/eu/eudat/EuDatApplication.java index 9c352e6ee..253cc8ff1 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/EuDatApplication.java +++ b/dmp-backend/web/src/main/java/eu/eudat/EuDatApplication.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import eu.eudat.data.BaseEntity; import org.jetbrains.annotations.NotNull; @@ -14,11 +15,14 @@ import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.scheduling.annotation.EnableAsync; +import java.util.List; + @SpringBootApplication(scanBasePackages = { "eu.eudat", "eu.eudat.depositinterface", @@ -33,24 +37,9 @@ public class EuDatApplication extends SpringBootServletInitializer { @Bean @Primary - public ObjectMapper primaryObjectMapper() { - return JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, true) - .serializationInclusion(JsonInclude.Include.NON_NULL) - .addModule(new JavaTimeModule()).build(); + public ObjectMapper primaryObjectMapper(Jackson2ObjectMapperBuilder builder) { + return builder.modulesToInstall(new JavaTimeModule()).build(); } -// @Bean -// public Jackson2ObjectMapperBuilder objectMapperBuilder() { -// return new Jackson2ObjectMapperBuilder() { -// -// @Override -// public void configure(ObjectMapper objectMapper) { -// objectMapper.registerModule(new JavaTimeModule()); -// super.configure(objectMapper); -// } -// }; -// -// } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/WebMVCConfiguration.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/WebMVCConfiguration.java index 23d5f66eb..a82b24d21 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/configurations/WebMVCConfiguration.java +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/WebMVCConfiguration.java @@ -1,11 +1,17 @@ package eu.eudat.configurations; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import eu.eudat.interceptors.UserInterceptor; import org.springframework.beans.factory.annotation.Autowired; 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.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; diff --git a/dmp-backend/web/src/main/resources/config/application.yml b/dmp-backend/web/src/main/resources/config/application.yml index 9d826cb3a..1e0ca9ee9 100644 --- a/dmp-backend/web/src/main/resources/config/application.yml +++ b/dmp-backend/web/src/main/resources/config/application.yml @@ -1,6 +1,10 @@ spring: jackson: default-property-inclusion: non_null + deserialization: + fail-on-unknown-properties: false + serialization: + write-dates-as-timestamps: false config: import: optional:classpath:config/app.env[.properties], optional:file:../config/app.env[.properties], optional:classpath:config/db.yml[.yml], optional:classpath:config/db-${spring.profiles.active}.yml[.yml], optional:file:../config/db-${spring.profiles.active}.yml[.yml],