From b7edbea60a30e717f6068d8ed5d561e9250926d2 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Thu, 25 Aug 2022 14:54:47 +0200 Subject: [PATCH] fix(java): more flexible json parser (#954) --- .../src/main/java/com/algolia/utils/JSONBuilder.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/JSONBuilder.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/JSONBuilder.java index dd6f7201e7..993c95570e 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/JSONBuilder.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/JSONBuilder.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.json.JsonMapper; +import static com.fasterxml.jackson.core.JsonGenerator.Feature; public class JSONBuilder { @@ -19,8 +20,11 @@ public ObjectMapper build() { ObjectMapper mapper = JsonMapper.builder().disable(MapperFeature.ALLOW_COERCION_OF_SCALARS).build(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, this.failOnUnknown); + mapper.enable(Feature.AUTO_CLOSE_JSON_CONTENT); mapper.enable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + mapper.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS); + mapper.disable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS); mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); return mapper;