-
Notifications
You must be signed in to change notification settings - Fork 109
Add Unixseconds serializer #181
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
Comments
This serializer has the unpleasant property of losing some information: it doesn't preserve the nanoseconds. Making it preserve the nanoseconds would lead to recreating the |
Sorry, with APIs I mean 3rd party JSON (REST) APIs which returns something like this: {
"timestamp": 123456789
} @Serializable
data class Result(@Serializable(with=InstantUnixSecondsSerializer::class) val timestamp: Instant) If you are able to change the json format, you could use instead |
I believe it would be reasonable to provide such serializer out-of-the-box if the unix seconds timestamps are indeed widespread in third-party json formats. The question is how to estimate how widespread they are, and whether we need a unix-millis-as-long serializer in addition to the proposed one. |
Just for the record: Unix timestamp does not include milliseconds by definition: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html A.4.16 |
It seems to be more wide-spread in the finance sector. So without doing deep research, I guess one can say the format is used often enough to warrant providing it out of the box. |
Interestingly, the YouTrack APIs also use Long unix timestamps for fields like |
Worth noting that the standard fields of a JWT use Unix epoch seconds to denote date times. https://en.wikipedia.org/wiki/JSON_Web_Token#Standard_fields |
Many APIs return a unix timestamp, the seconds from the epoch as
Long
.Although the serializer is easy to create, it could be provided.
The text was updated successfully, but these errors were encountered: