From f5fa229af76639fc440a030ae5ba6b24c4001627 Mon Sep 17 00:00:00 2001 From: Tom Winter Date: Tue, 10 Dec 2024 14:44:01 +0100 Subject: [PATCH] fix: ObjectMapperConfiguration --- .../rest/ObjectMapperConfiguration.kt | 14 +++++++++++++- .../src/main/resources/application.yaml | 6 ++++-- .../src/test/resources/application-e2e.yaml | 5 ++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/rest/ObjectMapperConfiguration.kt b/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/rest/ObjectMapperConfiguration.kt index 15342d8..50de803 100644 --- a/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/rest/ObjectMapperConfiguration.kt +++ b/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/rest/ObjectMapperConfiguration.kt @@ -6,10 +6,12 @@ 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 + @Configuration class ObjectMapperConfiguration { - + @Bean @Primary fun objectMapper(): ObjectMapper { @@ -20,4 +22,14 @@ class ObjectMapperConfiguration { ) return mapper.build() } + + @Bean + fun mappingJackson2HttpMessageConverter(): MappingJackson2HttpMessageConverter { + val builder = Jackson2ObjectMapperBuilder() + builder.featuresToEnable( + DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, + DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE + ) + return MappingJackson2HttpMessageConverter(builder.build()) + } } diff --git a/application/aam-backend-service/src/main/resources/application.yaml b/application/aam-backend-service/src/main/resources/application.yaml index 1721521..adcefd2 100644 --- a/application/aam-backend-service/src/main/resources/application.yaml +++ b/application/aam-backend-service/src/main/resources/application.yaml @@ -3,7 +3,10 @@ spring: name: aam-backend-service main: banner-mode: off - allow-bean-definition-overriding: true + jackson: + deserialization: + accept-empty-string-as-null-object: true + read-unknown-enum-values-using-default-value: true rabbitmq: listener: simple: @@ -21,7 +24,6 @@ spring: multipart: max-file-size: 5MB - server: servlet: context-path: /api diff --git a/application/aam-backend-service/src/test/resources/application-e2e.yaml b/application/aam-backend-service/src/test/resources/application-e2e.yaml index 6ec8591..f1b493d 100644 --- a/application/aam-backend-service/src/test/resources/application-e2e.yaml +++ b/application/aam-backend-service/src/test/resources/application-e2e.yaml @@ -3,7 +3,10 @@ spring: name: aam-backend-service main: banner-mode: off - allow-bean-definition-overriding: true + jackson: + deserialization: + accept-empty-string-as-null-object: true + read-unknown-enum-values-using-default-value: true rabbitmq: listener: simple: