From a14085dcd3ec784f32e8ff99430821e5f561e87f Mon Sep 17 00:00:00 2001 From: Dylan Hemsworth Date: Mon, 25 Nov 2024 09:16:22 -0800 Subject: [PATCH] Object mapper for spatial serialization --- .../bc/gov/nrs/wfprev/WfprevApiApplication.java | 17 +++++++++++++++++ .../wfprev/ProjectBoundaryControllerTest.java | 1 - .../nrs/wfprev/TestcontainersConfiguration.java | 2 -- .../test/java/resources/application.properties | 3 +++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 server/wfprev-api/src/test/java/resources/application.properties diff --git a/server/wfprev-api/src/main/java/ca/bc/gov/nrs/wfprev/WfprevApiApplication.java b/server/wfprev-api/src/main/java/ca/bc/gov/nrs/wfprev/WfprevApiApplication.java index 51e616479..3e6ec273c 100644 --- a/server/wfprev-api/src/main/java/ca/bc/gov/nrs/wfprev/WfprevApiApplication.java +++ b/server/wfprev-api/src/main/java/ca/bc/gov/nrs/wfprev/WfprevApiApplication.java @@ -9,6 +9,13 @@ import org.springframework.core.Ordered; import org.springframework.web.filter.ForwardedHeaderFilter; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.vividsolutions.jts.geom.Geometry; + +import ca.bc.gov.nrs.wfprev.common.serializers.GeoJsonJacksonDeserializer; +import ca.bc.gov.nrs.wfprev.common.serializers.GeoJsonJacksonSerializer; import jakarta.servlet.DispatcherType; @SpringBootApplication @@ -45,4 +52,14 @@ public FilterRegistrationBean forwardedHeaderFilter() { registration.setOrder(Ordered.HIGHEST_PRECEDENCE); return registration; } + + @Bean + public ObjectMapper registerObjectMapper(){ + ObjectMapper mapper = new ObjectMapper(); + SimpleModule simpleModule = new SimpleModule(); + simpleModule.addSerializer(new GeoJsonJacksonSerializer()); + simpleModule.addDeserializer(Geometry.class, new GeoJsonJacksonDeserializer()); + mapper.registerModule(simpleModule); + return mapper; + } } diff --git a/server/wfprev-api/src/test/java/ca/bc/gov/nrs/wfprev/ProjectBoundaryControllerTest.java b/server/wfprev-api/src/test/java/ca/bc/gov/nrs/wfprev/ProjectBoundaryControllerTest.java index cd01e6022..c06bc4c45 100644 --- a/server/wfprev-api/src/test/java/ca/bc/gov/nrs/wfprev/ProjectBoundaryControllerTest.java +++ b/server/wfprev-api/src/test/java/ca/bc/gov/nrs/wfprev/ProjectBoundaryControllerTest.java @@ -19,7 +19,6 @@ import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; -import com.fasterxml.jackson.core.Version; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.nimbusds.jose.shaded.gson.Gson; diff --git a/server/wfprev-api/src/test/java/ca/bc/gov/nrs/wfprev/TestcontainersConfiguration.java b/server/wfprev-api/src/test/java/ca/bc/gov/nrs/wfprev/TestcontainersConfiguration.java index c72cbf9d5..5f4b8f51e 100644 --- a/server/wfprev-api/src/test/java/ca/bc/gov/nrs/wfprev/TestcontainersConfiguration.java +++ b/server/wfprev-api/src/test/java/ca/bc/gov/nrs/wfprev/TestcontainersConfiguration.java @@ -12,7 +12,6 @@ @TestConfiguration(proxyBeanMethods = false) class TestcontainersConfiguration { - @Bean @ServiceConnection PostgreSQLContainer postgresContainer() { @@ -31,5 +30,4 @@ PostgreSQLContainer postgresContainer() { return container; } - } diff --git a/server/wfprev-api/src/test/java/resources/application.properties b/server/wfprev-api/src/test/java/resources/application.properties new file mode 100644 index 000000000..81b65e514 --- /dev/null +++ b/server/wfprev-api/src/test/java/resources/application.properties @@ -0,0 +1,3 @@ +spring.liquibase.change-log=classpath:db/main-changelog.xml +spring.liquibase.drop-first=true +spring.liquibase.contexts=test \ No newline at end of file