-
Notifications
You must be signed in to change notification settings - Fork 110
Rework the serializers using the DateTimeFormat API #415
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
base: master
Are you sure you want to change the base?
Conversation
314121a
to
aec4a6c
Compare
f678d42
to
a772c9e
Compare
a2af7bf
to
05f7e25
Compare
*/ | ||
public object InstantIso8601Serializer : KSerializer<Instant> { | ||
|
||
override val descriptor: SerialDescriptor = | ||
PrimitiveSerialDescriptor("kotlinx.datetime.Instant", PrimitiveKind.STRING) | ||
PrimitiveSerialDescriptor("kotlinx.datetime.Instant ISO", PrimitiveKind.STRING) |
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.
While there are no apparent restrictions on what can be used as a serial name, and no recommendations how to name multiple alternate serializers for the same type, this name may be used in error messages without quotes, so I think it would be better not to use spaces, so it can be read as one word.
Perhaps a slash can be used? E.g. kotlinx.datetime.Instant/ISO
, kotlinx.datetime.Instant/components
, and kotlinx.datetime.Instant/serializer/$customName
Or have we already come to a decision about the current serial descriptor naming scheme?
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.
I do remember that we have explicitly (but arbitrarily!) chosen spaces, yes, but the point about error messages was not raised at the time. The naming scheme you propose looks good.
The names of the serializers are still under discussion, but it's already decided that the serializers are going to be abstract classes. Fixes #350
Sometimes, `X.Formats.ISO` and `X.parse()`/`X.toString()` behave subtly differently; currently, it's the case for `LocalDateTime` and `LocalTime`. With this change, every entity that supports custom formats obtains a separate default serializer in addition to the ISO 8601 serializer, which now properly delegates to the corresponding `DateTimeFormat`. Fixes #351
User-visible error messages include serial descriptors verbatim.
05f7e25
to
a0f2c04
Compare
* See [Instant.parse] for details of how deserialization is performed. | ||
* | ||
* [name] is the name of the serializer. | ||
* The [SerialDescriptor.serialName] of the resulting serializer is `kotlinx.datetime.Instant serializer `[name]. |
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 update in docs of abstract serializers as well
Formats.ISO
instead oftoString
/parse
.DateTimeFormat
.Fixes #350
Fixes #351
Fixes #416