-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/add iso 8601 timestamp serialization #308
base: develop
Are you sure you want to change the base?
Conversation
…time or local + offset in serialization and deserialization
…01-timestamp-serialization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check my comments.
...main/java/io/americanexpress/synapse/utilities/common/serialization/InstantDeserializer.java
Show resolved
Hide resolved
...c/main/java/io/americanexpress/synapse/utilities/common/serialization/InstantSerializer.java
Show resolved
Hide resolved
.append(DateTimeFormatter.ISO_LOCAL_TIME) | ||
.appendLiteral('Z') | ||
.toFormatter() | ||
.withZone(ZoneOffset.UTC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we set the Zone, do we need to append the Literal Z
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we do otherwise, we end up getting the string back as "2024-08-30T14:48:34.857239"
even though the java Instant object value was actually 2024-08-30T14:48:34.857239Z
. The numbers all look correct but we miss the Z if we remove the appendLiteral
. If we remove the withZone
then we get a parsing error entirely
Currently ISO-8601 can't be serialized with the existing date time formatters when creating a
LocalDateTIme
object. Additionally, theLocalDateTime
object does not capture the current time in UTC which can lead to discrepancies across servers. To avoid this issue, we can use theInstant
class.This class captures a timezone in ISO-8601 format (yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'). There are 2 variations on the input:
2023-10-06T15:50Z
2023-10-06T15:50+02:00
will convert to2023-10-06T13:50Z
To enable this behavior, a custom serializer / deserializer is added to allow optional seconds. By default the seconds are not optional, only the milliseconds are.