Skip to content

Commit

Permalink
EPMRPP-88602 || refactor deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Apr 1, 2024
1 parent ebd10ab commit c0f07a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c0f07a9

Please sign in to comment.