Skip to content

Commit

Permalink
Converted ObjectMapperFactory to a singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
gmsdelmundo committed Sep 20, 2023
1 parent e7e1c65 commit 138add7
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/uid2/shared/Utils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/uid2/shared/store/parser/ClientParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Collection<ClientKey>> {
private static final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.build();
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();

@Override
public ParsingResult<Collection<ClientKey>> deserialize(InputStream inputStream) throws IOException {
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/uid2/shared/utils/Mapper.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 0 additions & 16 deletions src/main/java/com/uid2/shared/utils/ObjectMapperFactory.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/java/com/uid2/shared/auth/ClientKeyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/uid2/shared/auth/OperatorKeyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 138add7

Please sign in to comment.