Skip to content

Commit

Permalink
Bruk standard felles Jackson-mapper mot PDL (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolarsen authored Mar 23, 2022
1 parent 7e936cf commit 91e1817
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import no.nav.vedtak.exception.TekniskException;

@Deprecated // Bruk no.nav.vedtak.mapper.json.DefaultJsonMapper
@Deprecated(forRemoval = true) // Bruk no.nav.vedtak.mapper.json.DefaultJsonMapper
public class DefaultJsonMapper {

private DefaultJsonMapper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ public static ObjectMapper getObjectMapper() {
}

private static ObjectMapper createObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setTimeZone(TimeZone.getTimeZone("Europe/Oslo"));
mapper.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE);
return mapper;
return new ObjectMapper()
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule())
.setTimeZone(TimeZone.getTimeZone("Europe/Oslo"))
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true)
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE);
}

public static <T> List<T> fromJson(String json, TypeReference<List<T>> typeReference) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package no.nav.vedtak.felles.integrasjon.pdl;

import static com.fasterxml.jackson.core.JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN;
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY;
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
import static com.fasterxml.jackson.databind.PropertyNamingStrategies.LOWER_CAMEL_CASE;
import static com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS;
import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS;
import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS;
import static org.apache.http.HttpStatus.SC_ACCEPTED;
import static org.apache.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.http.HttpStatus.SC_NOT_MODIFIED;
Expand All @@ -16,7 +9,6 @@
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.List;
import java.util.TimeZone;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
Expand All @@ -28,8 +20,6 @@
import org.apache.http.util.EntityUtils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequest;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseProjection;
Expand All @@ -56,10 +46,11 @@
import no.nav.vedtak.felles.integrasjon.graphql.GraphQLErrorHandler;
import no.nav.vedtak.felles.integrasjon.rest.OidcRestClientResponseHandler.ObjectReaderResponseHandler;
import no.nav.vedtak.felles.integrasjon.rest.StsStandardXtraTokenRestKlient;
import no.nav.vedtak.mapper.json.DefaultJsonMapper;

@ApplicationScoped
public class PdlKlient implements Pdl {
private static final ObjectMapper MAPPER = mapper();
private static final ObjectMapper MAPPER = DefaultJsonMapper.getObjectMapper();
@Deprecated(forRemoval = true, since = "3.0.x")
public static final String PDL_KLIENT_NOT_FOUND_KODE = Pdl.PDL_KLIENT_NOT_FOUND_KODE;
private static final List<Integer> HTTP_KODER_TOM_RESPONS = List.of(SC_NOT_MODIFIED, SC_NO_CONTENT, SC_ACCEPTED);
Expand Down Expand Up @@ -158,20 +149,6 @@ private HttpPost post(GraphQLRequest req) {
}
}

private static ObjectMapper mapper() {
return new ObjectMapper()
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule())
.setPropertyNamingStrategy(LOWER_CAMEL_CASE)
.setTimeZone(TimeZone.getTimeZone("Europe/Oslo"))
.disable(WRITE_DATES_AS_TIMESTAMPS)
.disable(WRITE_DURATIONS_AS_TIMESTAMPS)
.disable(FAIL_ON_EMPTY_BEANS)
.configure(WRITE_BIGDECIMAL_AS_PLAIN, true)
.enable(FAIL_ON_READING_DUP_TREE_KEY)
.enable(FAIL_ON_UNKNOWN_PROPERTIES);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [endpoint=" + endpoint + ", restKlient=" + restKlient + ", errorHandler=" + errorHandler + "]";
Expand Down

0 comments on commit 91e1817

Please sign in to comment.