Serialise Instant as ISO 8601 string, Duration as number of milliseconds, and allow registering of custom TypeAdapterFactories#390
Open
Serialise Instant as ISO 8601 string, Duration as number of milliseconds, and allow registering of custom TypeAdapterFactories#390
Conversation
45b872a to
00d0a31
Compare
mchitre
approved these changes
Mar 25, 2026
Collaborator
Author
|
Moved the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR bundles two unrelated changes.
Serialisation of Instant and Duration
By default, Gson serialises
java.time.Instantandjava.time.Durationobjects as JSON objects withsecondsandnanosfields (same JSON format for both Java classes).This representation feels needlessly Java-specific. This PR proposes to serialise
Instantvalues as ISO 8601 strings ("2026-03-23T05:20:06.323Z"), andDurationvalues as number of milliseconds (1000== 1 second) instead. The rationale behind this is that ISO 8601 strings are instantly human-readable and easily parsable in any reasonable language (including C), and fjage already uses milliseconds in many places to represent durations.Support custom type adapter factories
Fjage already supports registering of custom type hierarchy adapters, but not type adapter factories. I'm assuming the only reason for this is that so far no one had a need for type adapter factories, but now I do. Therefore, I've added a new method
JsonMessage.addTypeAdapterFactory().