Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/main/java/com/mindee/http/MindeeHttpApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.mindee.MindeeException;
import com.mindee.MindeeSettings;
import com.mindee.parsing.common.ApiResponse;
Expand Down Expand Up @@ -40,7 +41,7 @@
*/
public final class MindeeHttpApi extends MindeeApi {

private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectMapper mapper = JsonMapper.builder().findAndAddModules().build();
private final Function<Endpoint, String> buildProductPredicBasetUrl = this::buildProductPredictBaseUrl;
private final Function<String, String> buildWorkflowPredictBaseUrl = this::buildWorkflowPredictBaseUrl;
private final Function<String, String> buildWorkflowExecutionBaseUrl = this::buildWorkflowExecutionUrl;
Expand Down Expand Up @@ -146,8 +147,6 @@ public <DocT extends Inference> AsyncPredictResponse<DocT> documentQueueGet(
String endpointUrl = documentUrlFromEndpoint.apply(endpoint).concat(jobId);
HttpGet get = new HttpGet(endpointUrl);

// required to register jackson date module format to deserialize
mapper.findAndRegisterModules();
JavaType parametricType = mapper
.getTypeFactory()
.constructParametricType(AsyncPredictResponse.class, documentClass);
Expand Down Expand Up @@ -198,8 +197,6 @@ public <DocT extends Inference> PredictResponse<DocT> predictPost(
String url = urlFromEndpoint.apply(endpoint);
HttpPost post = buildHttpPost(url, requestParameters);

// required to register jackson date module format to deserialize
mapper.findAndRegisterModules();
JavaType parametricType = mapper
.getTypeFactory()
.constructParametricType(PredictResponse.class, documentClass);
Expand Down Expand Up @@ -240,8 +237,6 @@ public <DocT extends Inference> AsyncPredictResponse<DocT> predictAsyncPost(
}
HttpPost post = buildHttpPost(url, requestParameters);

// required to register jackson date module format to deserialize
mapper.findAndRegisterModules();
JavaType parametricType = mapper
.getTypeFactory()
.constructParametricType(AsyncPredictResponse.class, documentClass);
Expand Down Expand Up @@ -277,8 +272,6 @@ public <DocT extends Inference> WorkflowResponse<DocT> executeWorkflowPost(
String url = workflowUrlFromId.apply(workflowId);
HttpPost post = buildHttpPost(url, requestParameters);

// required to register jackson date module format to deserialize
mapper.findAndRegisterModules();
JavaType parametricType = mapper
.getTypeFactory()
.constructParametricType(WorkflowResponse.class, documentClass);
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/mindee/http/MindeeHttpApiV2.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mindee.http;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.mindee.MindeeException;
import com.mindee.MindeeSettingsV2;
import com.mindee.input.LocalInputSource;
Expand Down Expand Up @@ -33,7 +34,7 @@
*/
public final class MindeeHttpApiV2 extends MindeeApiV2 {

private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectMapper mapper = JsonMapper.builder().findAndAddModules().build();

/**
* The MindeeSetting needed to make the api call.
Expand Down Expand Up @@ -115,7 +116,6 @@ public JobResponse reqPostEnqueue(URLInputSource inputSource, BaseParameters opt
* @return a valid job response.
*/
private JobResponse executeEnqueue(HttpPost post) {
mapper.findAndRegisterModules();
try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
return httpClient.execute(post, response -> {
HttpEntity responseEntity = response.getEntity();
Expand Down Expand Up @@ -149,7 +149,6 @@ public JobResponse reqGetJob(String jobId) {
RequestConfig noRedirect = RequestConfig.custom().setRedirectsEnabled(false).build();
get.setConfig(noRedirect);

mapper.findAndRegisterModules();
try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
return httpClient.execute(get, response -> {
HttpEntity responseEntity = response.getEntity();
Expand Down Expand Up @@ -190,8 +189,6 @@ public <TResponse extends CommonResponse> TResponse reqGetResult(
}
get.setHeader(HttpHeaders.USER_AGENT, getUserAgent());

mapper.findAndRegisterModules();

try (CloseableHttpClient httpClient = httpClientBuilder.build()) {

return httpClient.execute(get, response -> {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mindee/input/LocalResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@Getter
public class LocalResponse {
private final byte[] file;
private static final ObjectMapper mapper = new ObjectMapper();

/**
* Load from an {@link InputStream}.
Expand Down
Loading