From 8b7a4f75a4db2ff18e056ffb7f71678683ea742e Mon Sep 17 00:00:00 2001 From: julien-pinta-pivot Date: Mon, 16 Mar 2026 17:26:56 +0100 Subject: [PATCH] :bug: Use new style, static object mapper to avoid recreating multiple times --- src/main/java/com/mindee/http/MindeeHttpApi.java | 11 ++--------- src/main/java/com/mindee/http/MindeeHttpApiV2.java | 7 ++----- src/main/java/com/mindee/input/LocalResponse.java | 1 + 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/mindee/http/MindeeHttpApi.java b/src/main/java/com/mindee/http/MindeeHttpApi.java index 3e97434e4..226d94a1e 100644 --- a/src/main/java/com/mindee/http/MindeeHttpApi.java +++ b/src/main/java/com/mindee/http/MindeeHttpApi.java @@ -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; @@ -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 buildProductPredicBasetUrl = this::buildProductPredictBaseUrl; private final Function buildWorkflowPredictBaseUrl = this::buildWorkflowPredictBaseUrl; private final Function buildWorkflowExecutionBaseUrl = this::buildWorkflowExecutionUrl; @@ -146,8 +147,6 @@ public AsyncPredictResponse 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); @@ -198,8 +197,6 @@ public PredictResponse 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); @@ -240,8 +237,6 @@ public AsyncPredictResponse 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); @@ -277,8 +272,6 @@ public WorkflowResponse 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); diff --git a/src/main/java/com/mindee/http/MindeeHttpApiV2.java b/src/main/java/com/mindee/http/MindeeHttpApiV2.java index 735a7d63c..0f15df371 100644 --- a/src/main/java/com/mindee/http/MindeeHttpApiV2.java +++ b/src/main/java/com/mindee/http/MindeeHttpApiV2.java @@ -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; @@ -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. @@ -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(); @@ -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(); @@ -190,8 +189,6 @@ public TResponse reqGetResult( } get.setHeader(HttpHeaders.USER_AGENT, getUserAgent()); - mapper.findAndRegisterModules(); - try (CloseableHttpClient httpClient = httpClientBuilder.build()) { return httpClient.execute(get, response -> { diff --git a/src/main/java/com/mindee/input/LocalResponse.java b/src/main/java/com/mindee/input/LocalResponse.java index 437a1f043..bddbafd89 100644 --- a/src/main/java/com/mindee/input/LocalResponse.java +++ b/src/main/java/com/mindee/input/LocalResponse.java @@ -26,6 +26,7 @@ @Getter public class LocalResponse { private final byte[] file; + private static final ObjectMapper mapper = new ObjectMapper(); /** * Load from an {@link InputStream}.