From c0f07a9b29cd2aa263e209b86389391fe5258982 Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Mon, 1 Apr 2024 09:20:26 +0300 Subject: [PATCH] EPMRPP-88602 || refactor deserializer --- .../ws/reporting/databind/MultiFormatDateDeserializer.java | 7 ++++++- .../deserializers/MultiFormatDateDeserializerTest.java | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java b/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java index 0dedd45..6660970 100644 --- a/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java +++ b/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java @@ -26,7 +26,6 @@ import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; -import java.time.format.DateTimeParseException; /** * Deserialization class for parsing incoming dates of different formats. @@ -48,6 +47,12 @@ public Instant deserialize(JsonParser parser, DeserializationContext context) th if (longDate > 0) { return Instant.ofEpochMilli(longDate); } + try { + long millis = Long.parseLong(parser.getText()); + return Instant.ofEpochMilli(millis); + } catch (NumberFormatException e) { + // ignore + } String strDate = parser.getText(); DateTimeFormatter formatter = diff --git a/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java b/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java index 4bbdfaf..81a70a7 100644 --- a/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java +++ b/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java @@ -48,6 +48,7 @@ class MultiFormatDateDeserializerTest { "2024-03-01T20:24:09.930Z", "2024-03-01T20:24:09.930", "2024-03-01T20:24:09.930+00:00", + "1709324649930" }) void deserializeDates(String strDate) throws IOException { MultiFormatDateDeserializer a = new MultiFormatDateDeserializer();