summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul-Christian Volkmer2026-04-24 11:19:28 +0200
committerGitHub2026-04-24 09:19:28 +0000
commit615115dad8fb260bea6ea3436c1d239777b42df1 (patch)
tree585602883907688cb77980da655c9989397bbecd /src
parent185a35a1e02adcddd42d25861b19b4360071368b (diff)
refactor: JacksonConfig for deprecated MappingJackson2HttpMessageConverter (#285)
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/config/ConsentResourceDeserializer.kt19
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/config/ConsentResourceSerializer.kt17
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/config/FhirResourceModule.kt11
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/config/JacksonConfig.kt39
-rw-r--r--src/test/kotlin/dev/dnpm/etl/processor/config/JacksonConfigTest.kt50
5 files changed, 86 insertions, 50 deletions
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/ConsentResourceDeserializer.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/ConsentResourceDeserializer.kt
deleted file mode 100644
index 48163a1..0000000
--- a/src/main/kotlin/dev/dnpm/etl/processor/config/ConsentResourceDeserializer.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package dev.dnpm.etl.processor.config
-
-import com.fasterxml.jackson.core.JsonParser
-import com.fasterxml.jackson.databind.DeserializationContext
-import com.fasterxml.jackson.databind.JsonDeserializer
-import com.fasterxml.jackson.databind.JsonNode
-import org.hl7.fhir.r4.model.Consent
-
-class ConsentResourceDeserializer : JsonDeserializer<Consent>() {
- override fun deserialize(
- p: JsonParser?,
- ctxt: DeserializationContext?,
- ): Consent {
- val jsonNode = p?.readValueAsTree<JsonNode>()
- val json = jsonNode?.toString()
-
- return JacksonConfig.fhirContext().newJsonParser().parseResource(json) as Consent
- }
-}
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/ConsentResourceSerializer.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/ConsentResourceSerializer.kt
deleted file mode 100644
index b4f29a4..0000000
--- a/src/main/kotlin/dev/dnpm/etl/processor/config/ConsentResourceSerializer.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package dev.dnpm.etl.processor.config
-
-import com.fasterxml.jackson.core.JsonGenerator
-import com.fasterxml.jackson.databind.JsonSerializer
-import com.fasterxml.jackson.databind.SerializerProvider
-import org.hl7.fhir.r4.model.Consent
-
-class ConsentResourceSerializer : JsonSerializer<Consent>() {
- override fun serialize(
- value: Consent,
- gen: JsonGenerator,
- serializers: SerializerProvider,
- ) {
- val json = JacksonConfig.fhirContext().newJsonParser().encodeResourceToString(value)
- gen.writeRawValue(json)
- }
-}
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/FhirResourceModule.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/FhirResourceModule.kt
deleted file mode 100644
index 45a3d93..0000000
--- a/src/main/kotlin/dev/dnpm/etl/processor/config/FhirResourceModule.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package dev.dnpm.etl.processor.config
-
-import com.fasterxml.jackson.databind.module.SimpleModule
-import org.hl7.fhir.r4.model.Consent
-
-class FhirResourceModule : SimpleModule() {
- init {
- addSerializer(Consent::class.java, ConsentResourceSerializer())
- addDeserializer(Consent::class.java, ConsentResourceDeserializer())
- }
-}
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/JacksonConfig.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/JacksonConfig.kt
index 2480de8..847880d 100644
--- a/src/main/kotlin/dev/dnpm/etl/processor/config/JacksonConfig.kt
+++ b/src/main/kotlin/dev/dnpm/etl/processor/config/JacksonConfig.kt
@@ -2,10 +2,13 @@ package dev.dnpm.etl.processor.config
import ca.uhn.fhir.context.FhirContext
import com.fasterxml.jackson.annotation.JsonInclude
-import com.fasterxml.jackson.databind.ObjectMapper
-import com.fasterxml.jackson.databind.SerializationFeature
+import com.fasterxml.jackson.core.JsonGenerator
+import com.fasterxml.jackson.core.JsonParser
+import com.fasterxml.jackson.databind.*
+import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
+import org.hl7.fhir.r4.model.Consent
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@@ -20,9 +23,39 @@ class JacksonConfig {
@Bean
fun objectMapper(): ObjectMapper =
ObjectMapper()
- .registerModule(FhirResourceModule())
+ .registerModule(Jackson2FhirResourceModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.registerModule(JavaTimeModule())
.registerModule(Jdk8Module())
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
}
+
+class Jackson2FhirResourceModule : SimpleModule() {
+ init {
+ addSerializer(Consent::class.java, Jackson2ConsentResourceSerializer())
+ addDeserializer(Consent::class.java, Jackson2ConsentResourceDeserializer())
+ }
+}
+
+class Jackson2ConsentResourceSerializer : JsonSerializer<Consent>() {
+ override fun serialize(
+ value: Consent,
+ gen: JsonGenerator,
+ serializers: SerializerProvider,
+ ) {
+ val json = JacksonConfig.fhirContext().newJsonParser().encodeResourceToString(value)
+ gen.writeRawValue(json)
+ }
+}
+
+class Jackson2ConsentResourceDeserializer : JsonDeserializer<Consent>() {
+ override fun deserialize(
+ p: JsonParser?,
+ ctxt: DeserializationContext?,
+ ): Consent {
+ val jsonNode = p?.readValueAsTree<JsonNode>()
+ val json = jsonNode?.toString()
+
+ return JacksonConfig.fhirContext().newJsonParser().parseResource(json) as Consent
+ }
+}
diff --git a/src/test/kotlin/dev/dnpm/etl/processor/config/JacksonConfigTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/config/JacksonConfigTest.kt
new file mode 100644
index 0000000..9042d8c
--- /dev/null
+++ b/src/test/kotlin/dev/dnpm/etl/processor/config/JacksonConfigTest.kt
@@ -0,0 +1,50 @@
+package dev.dnpm.etl.processor.config
+
+import org.assertj.core.api.Assertions.assertThat
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.params.ParameterizedTest
+import org.junit.jupiter.params.provider.ValueSource
+import java.util.*
+
+class JacksonConfigTest {
+
+ lateinit var jacksonConfig: JacksonConfig
+
+ @BeforeEach
+ fun setup() {
+ this.jacksonConfig = JacksonConfig()
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = [
+ "mv64e-mtb-fake-patient.json",
+ "fake_broadConsent_mii_response_deny.json",
+ "fake_broadConsent_mii_response_permit.json",
+ ])
+ fun shouldSerializeJsonWithoutNulledOutFields(filename: String) {
+ val inputJson =
+ Objects.requireNonNull(this.javaClass.classLoader.getResourceAsStream(filename))?.readAllBytes()?.decodeToString()
+
+ val json = this.jacksonConfig.objectMapper().readTree(inputJson)
+ val actual = this.jacksonConfig.objectMapper().writeValueAsString(json)
+
+ assertThat(actual).doesNotContain("null")
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = [
+ "fake_broadConsent_mii_response_deny.json",
+ "fake_broadConsent_mii_response_permit.json",
+ ])
+ fun shouldSerializeConsentWithoutWithoutDatesAsTimestamps(filename: String) {
+ val inputJson =
+ Objects.requireNonNull(this.javaClass.classLoader.getResourceAsStream(filename))?.readAllBytes()?.decodeToString()
+
+ val json = this.jacksonConfig.objectMapper().readTree(inputJson)
+ val actual = this.jacksonConfig.objectMapper().writeValueAsString(json)
+
+ assertThat(actual).contains(""""lastUpdated":"2025-08-15T11:13:59.143+02:00"""")
+ }
+
+}