diff --git a/client/src/main/java/simplyrestful/api/framework/client/SimplyRESTfulClient.java b/client/src/main/java/simplyrestful/api/framework/client/SimplyRESTfulClient.java index f323c9e1..6e4c3bfa 100644 --- a/client/src/main/java/simplyrestful/api/framework/client/SimplyRESTfulClient.java +++ b/client/src/main/java/simplyrestful/api/framework/client/SimplyRESTfulClient.java @@ -23,10 +23,11 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; import io.openapitools.jackson.dataformat.hal.HALLink; -import io.openapitools.jackson.dataformat.hal.HALMapper; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.PathItem; @@ -56,13 +57,15 @@ public class SimplyRESTfulClient { private final String resourceProfile; private final MediaType resourceMediaType; private final Client client; + private final ObjectMapper halMapper; - SimplyRESTfulClient(Client client, URI baseApiUri, Class resourceClass) { + SimplyRESTfulClient(Client client, ObjectMapper halMapper, URI baseApiUri, Class resourceClass) { this.baseApiUri = baseApiUri; this.client = client; if (!client.getConfiguration().isRegistered(JacksonJsonProvider.class)) { - client.register(new JacksonJsonProvider(new HALMapper())); + client.register(new JacksonJsonProvider(halMapper)); } + this.halMapper = halMapper; this.resourceClass = resourceClass; this.resourceProfile = discoverResourceProfile(); this.resourceMediaType = detectResourceMediaType(); @@ -196,7 +199,8 @@ private HALCollection retrievePagedCollection(int page, int pageSize, boolean private S deserializeJson(String jsonString, Class deserializationClass) { try { - return new HALMapper().readValue(jsonString, deserializationClass); + ObjectMapper mapper = halMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + return mapper.readValue(jsonString, deserializationClass); } catch (JsonProcessingException e) { throw new RuntimeException(e); } @@ -204,7 +208,8 @@ private S deserializeJson(String jsonString, Class deserializationClass) private S deserializeJsonWithGenerics(String jsonString, TypeReference typeRef) { try { - return new HALMapper().readValue(jsonString, typeRef); + ObjectMapper mapper = halMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + return mapper.readValue(jsonString, typeRef); } catch (JsonProcessingException e) { throw new RuntimeException(e); } diff --git a/client/src/main/java/simplyrestful/api/framework/client/SimplyRESTfulClientFactory.java b/client/src/main/java/simplyrestful/api/framework/client/SimplyRESTfulClientFactory.java index 7b4bab3a..e227ad0f 100644 --- a/client/src/main/java/simplyrestful/api/framework/client/SimplyRESTfulClientFactory.java +++ b/client/src/main/java/simplyrestful/api/framework/client/SimplyRESTfulClientFactory.java @@ -6,18 +6,28 @@ import javax.inject.Named; import javax.ws.rs.client.Client; +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.openapitools.jackson.dataformat.hal.HALMapper; import simplyrestful.api.framework.resources.HALResource; @Named public class SimplyRESTfulClientFactory { private final Client client; + private ObjectMapper halMapper; @Inject public SimplyRESTfulClientFactory(Client client) { this.client = client; + this.halMapper = new HALMapper(); + } + + public SimplyRESTfulClientFactory withMapper(ObjectMapper halMapper){ + this.halMapper = halMapper; + return this; } public SimplyRESTfulClient newClient(URI baseApiUri, Class resourceClass){ - return new SimplyRESTfulClient(client, baseApiUri, resourceClass); + return new SimplyRESTfulClient(client, halMapper, baseApiUri, resourceClass); } }