diff --git a/src/main/java/com/uid2/shared/Utils.java b/src/main/java/com/uid2/shared/Utils.java index 6b9ccb98..48b01e70 100644 --- a/src/main/java/com/uid2/shared/Utils.java +++ b/src/main/java/com/uid2/shared/Utils.java @@ -1,7 +1,7 @@ package com.uid2.shared; import com.fasterxml.jackson.databind.ObjectMapper; -import com.uid2.shared.utils.ObjectMapperFactory; +import com.uid2.shared.utils.Mapper; import io.vertx.core.json.Json; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; @@ -24,7 +24,7 @@ public class Utils { public static final String OS = System.getProperty("os.name").toLowerCase(); public static final boolean IsWindows = OS.contains("win"); - private static final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.build(); + private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance(); public static boolean isProductionEnvironment() { // detect if it is running in KUBERNETES_SERVICE_HOST diff --git a/src/main/java/com/uid2/shared/auth/RotatingOperatorKeyProvider.java b/src/main/java/com/uid2/shared/auth/RotatingOperatorKeyProvider.java index 5493c61b..161e0b28 100644 --- a/src/main/java/com/uid2/shared/auth/RotatingOperatorKeyProvider.java +++ b/src/main/java/com/uid2/shared/auth/RotatingOperatorKeyProvider.java @@ -9,7 +9,7 @@ import com.uid2.shared.store.reader.IMetadataVersionedStore; import com.uid2.shared.store.IOperatorKeyProvider; import com.uid2.shared.store.scope.StoreScope; -import com.uid2.shared.utils.ObjectMapperFactory; +import com.uid2.shared.utils.Mapper; import io.vertx.core.json.JsonObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,7 +20,7 @@ public class RotatingOperatorKeyProvider implements IOperatorKeyProvider, IMetadataVersionedStore { private static final Logger LOGGER = LoggerFactory.getLogger(RotatingOperatorKeyProvider.class); - private static final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.build(); + private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance(); private final DownloadCloudStorage metadataStreamProvider; private final DownloadCloudStorage contentStreamProvider; diff --git a/src/main/java/com/uid2/shared/store/parser/ClientParser.java b/src/main/java/com/uid2/shared/store/parser/ClientParser.java index 0ca1d8ed..dc343f49 100644 --- a/src/main/java/com/uid2/shared/store/parser/ClientParser.java +++ b/src/main/java/com/uid2/shared/store/parser/ClientParser.java @@ -2,16 +2,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.uid2.shared.auth.ClientKey; -import com.uid2.shared.utils.ObjectMapperFactory; +import com.uid2.shared.utils.Mapper; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Collection; -import java.util.List; public class ClientParser implements Parser> { - private static final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.build(); + private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance(); @Override public ParsingResult> deserialize(InputStream inputStream) throws IOException { diff --git a/src/main/java/com/uid2/shared/utils/Mapper.java b/src/main/java/com/uid2/shared/utils/Mapper.java new file mode 100644 index 00000000..60b7b694 --- /dev/null +++ b/src/main/java/com/uid2/shared/utils/Mapper.java @@ -0,0 +1,18 @@ +package com.uid2.shared.utils; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class Mapper { + private static final ObjectMapper INSTANCE = new ObjectMapper() + .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);; + + private Mapper() { + } + + public static ObjectMapper getInstance() { + return INSTANCE; + } +} diff --git a/src/main/java/com/uid2/shared/utils/ObjectMapperFactory.java b/src/main/java/com/uid2/shared/utils/ObjectMapperFactory.java deleted file mode 100644 index 269a48e6..00000000 --- a/src/main/java/com/uid2/shared/utils/ObjectMapperFactory.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.uid2.shared.utils; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class ObjectMapperFactory { - private ObjectMapperFactory() { - } - - public static ObjectMapper build() { - return new ObjectMapper() - .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true) - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - } -} diff --git a/src/test/java/com/uid2/shared/auth/ClientKeyTest.java b/src/test/java/com/uid2/shared/auth/ClientKeyTest.java index 64e05de9..f76d9732 100644 --- a/src/test/java/com/uid2/shared/auth/ClientKeyTest.java +++ b/src/test/java/com/uid2/shared/auth/ClientKeyTest.java @@ -2,14 +2,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.uid2.shared.utils.ObjectMapperFactory; +import com.uid2.shared.utils.Mapper; import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; public class ClientKeyTest { - private static final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.build(); + private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance(); @Test public void verifyDisabledPropIsOptional() throws JsonProcessingException { diff --git a/src/test/java/com/uid2/shared/auth/OperatorKeyTest.java b/src/test/java/com/uid2/shared/auth/OperatorKeyTest.java index b2091f0b..ed3cbdf8 100644 --- a/src/test/java/com/uid2/shared/auth/OperatorKeyTest.java +++ b/src/test/java/com/uid2/shared/auth/OperatorKeyTest.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.uid2.shared.utils.ObjectMapperFactory; +import com.uid2.shared.utils.Mapper; import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.*; public class OperatorKeyTest { - private static final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.build(); + private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance(); @Test public void verifyDisabledPropIsOptional() throws JsonProcessingException { diff --git a/src/test/java/com/uid2/shared/utils/ObjectMapperFactoryTest.java b/src/test/java/com/uid2/shared/utils/MapperTest.java similarity index 94% rename from src/test/java/com/uid2/shared/utils/ObjectMapperFactoryTest.java rename to src/test/java/com/uid2/shared/utils/MapperTest.java index f719a465..020b2d8c 100644 --- a/src/test/java/com/uid2/shared/utils/ObjectMapperFactoryTest.java +++ b/src/test/java/com/uid2/shared/utils/MapperTest.java @@ -9,8 +9,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class ObjectMapperFactoryTest { - private static final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.build(); +public class MapperTest { + private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance(); @Test public void readValue_whenEnumIsCaseInsensitive() throws Exception {