Skip to content

Commit 10186f7

Browse files
Register to modules the new way
1 parent 260d1b2 commit 10186f7

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/main/java/com/mindee/http/MindeeHttpApi.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.JavaType;
55
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.databind.json.JsonMapper;
67
import com.mindee.MindeeException;
78
import com.mindee.MindeeSettings;
89
import com.mindee.parsing.common.ApiResponse;
@@ -40,7 +41,9 @@
4041
*/
4142
public final class MindeeHttpApi extends MindeeApi {
4243

43-
private static final ObjectMapper mapper = new ObjectMapper();
44+
private static final ObjectMapper mapper = JsonMapper.builder()
45+
.findAndAddModules()
46+
.build();
4447
private final Function<Endpoint, String> buildProductPredicBasetUrl = this::buildProductPredictBaseUrl;
4548
private final Function<String, String> buildWorkflowPredictBaseUrl = this::buildWorkflowPredictBaseUrl;
4649
private final Function<String, String> buildWorkflowExecutionBaseUrl = this::buildWorkflowExecutionUrl;
@@ -146,8 +149,6 @@ public <DocT extends Inference> AsyncPredictResponse<DocT> documentQueueGet(
146149
String endpointUrl = documentUrlFromEndpoint.apply(endpoint).concat(jobId);
147150
HttpGet get = new HttpGet(endpointUrl);
148151

149-
// required to register jackson date module format to deserialize
150-
mapper.findAndRegisterModules();
151152
JavaType parametricType = mapper
152153
.getTypeFactory()
153154
.constructParametricType(AsyncPredictResponse.class, documentClass);
@@ -198,8 +199,6 @@ public <DocT extends Inference> PredictResponse<DocT> predictPost(
198199
String url = urlFromEndpoint.apply(endpoint);
199200
HttpPost post = buildHttpPost(url, requestParameters);
200201

201-
// required to register jackson date module format to deserialize
202-
mapper.findAndRegisterModules();
203202
JavaType parametricType = mapper
204203
.getTypeFactory()
205204
.constructParametricType(PredictResponse.class, documentClass);
@@ -240,8 +239,6 @@ public <DocT extends Inference> AsyncPredictResponse<DocT> predictAsyncPost(
240239
}
241240
HttpPost post = buildHttpPost(url, requestParameters);
242241

243-
// required to register jackson date module format to deserialize
244-
mapper.findAndRegisterModules();
245242
JavaType parametricType = mapper
246243
.getTypeFactory()
247244
.constructParametricType(AsyncPredictResponse.class, documentClass);
@@ -277,8 +274,6 @@ public <DocT extends Inference> WorkflowResponse<DocT> executeWorkflowPost(
277274
String url = workflowUrlFromId.apply(workflowId);
278275
HttpPost post = buildHttpPost(url, requestParameters);
279276

280-
// required to register jackson date module format to deserialize
281-
mapper.findAndRegisterModules();
282277
JavaType parametricType = mapper
283278
.getTypeFactory()
284279
.constructParametricType(WorkflowResponse.class, documentClass);

src/main/java/com/mindee/http/MindeeHttpApiV2.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mindee.http;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.json.JsonMapper;
45
import com.mindee.MindeeException;
56
import com.mindee.MindeeSettingsV2;
67
import com.mindee.input.LocalInputSource;
@@ -33,7 +34,9 @@
3334
*/
3435
public final class MindeeHttpApiV2 extends MindeeApiV2 {
3536

36-
private static final ObjectMapper mapper = new ObjectMapper();
37+
private static final ObjectMapper mapper = JsonMapper.builder()
38+
.findAndAddModules()
39+
.build();
3740

3841
/**
3942
* The MindeeSetting needed to make the api call.
@@ -115,7 +118,6 @@ public JobResponse reqPostEnqueue(URLInputSource inputSource, BaseParameters opt
115118
* @return a valid job response.
116119
*/
117120
private JobResponse executeEnqueue(HttpPost post) {
118-
mapper.findAndRegisterModules();
119121
try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
120122
return httpClient.execute(post, response -> {
121123
HttpEntity responseEntity = response.getEntity();
@@ -149,7 +151,6 @@ public JobResponse reqGetJob(String jobId) {
149151
RequestConfig noRedirect = RequestConfig.custom().setRedirectsEnabled(false).build();
150152
get.setConfig(noRedirect);
151153

152-
mapper.findAndRegisterModules();
153154
try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
154155
return httpClient.execute(get, response -> {
155156
HttpEntity responseEntity = response.getEntity();
@@ -190,8 +191,6 @@ public <TResponse extends CommonResponse> TResponse reqGetResult(
190191
}
191192
get.setHeader(HttpHeaders.USER_AGENT, getUserAgent());
192193

193-
mapper.findAndRegisterModules();
194-
195194
try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
196195

197196
return httpClient.execute(get, response -> {

0 commit comments

Comments
 (0)