From ec4063e49d78074bb8c479fcd080039592666297 Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Wed, 27 Nov 2024 23:23:45 +0300 Subject: [PATCH] Instant time POC --- build.gradle | 1 + .../utils/http/HttpRequestUtils.java | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 2b6de0d8..e23676e9 100644 --- a/build.gradle +++ b/build.gradle @@ -47,6 +47,7 @@ dependencies { api 'com.fasterxml.jackson.core:jackson-databind:2.12.7.1' // Access is needed by HTTP loggers to format JSON api 'io.reactivex.rxjava2:rxjava:2.2.10' api 'com.google.code.findbugs:jsr305:3.0.2' + api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.0' api ("com.squareup.retrofit2:retrofit:${project.retrofit_version}") { exclude module: 'okhttp' diff --git a/src/main/java/com/epam/reportportal/utils/http/HttpRequestUtils.java b/src/main/java/com/epam/reportportal/utils/http/HttpRequestUtils.java index 069f9f61..adbf30b0 100644 --- a/src/main/java/com/epam/reportportal/utils/http/HttpRequestUtils.java +++ b/src/main/java/com/epam/reportportal/utils/http/HttpRequestUtils.java @@ -23,8 +23,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.epam.reportportal.utils.files.ByteSource; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import okhttp3.MultipartBody; import okhttp3.RequestBody; import org.slf4j.Logger; @@ -43,13 +48,15 @@ public class HttpRequestUtils { private static final Logger LOGGER = LoggerFactory.getLogger(HttpRequestUtils.class); public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; - public static final ObjectMapper MAPPER; - - static { - MAPPER = new ObjectMapper(); - MAPPER.setDateFormat(new SimpleDateFormat(DEFAULT_DATE_FORMAT)); - MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - } + public static final ObjectMapper MAPPER = JsonMapper.builder() + .addModule(new JavaTimeModule()) + .annotationIntrospector(new JacksonAnnotationIntrospector()) + .configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) + .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false) + .addModule(new JavaTimeModule()) + .build(); private static final String DEFAULT_TYPE = "application/octet-stream";