-
Notifications
You must be signed in to change notification settings - Fork 82
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
Deserialize time as Duration
#586
Deserialize time as Duration
#586
Conversation
In places where I had to annotate type parameters like val rateLimitPerUser: Optional<@Serializable(with = DurationInSecondsSerializer::class) Duration> = Optional.Missing() I've added import aliases to make it shorter and more readable val rateLimitPerUser: Optional<@Serializable(InSeconds::class) Duration> = Optional.Missing() Edit: typealias DurationInSeconds = @Serializable(with = DurationInSecondsSerializer::class) Duration
val rateLimitPerUser: Optional<DurationInSeconds> = Optional.Missing() |
I haven't changed the type to I suggest to only do this in places where the time unit is not already part of the property name (like Edit: |
The
Duration
type is Kotlin's way to express time amounts.However, it is not serializable by default and time is serialized in different units across Discord's API.
To make
Duration
usable in serializable classes, this PR introduces a serializer for everyDurationUnit
that (de-)serializesDuration
s as an integer number of the respectiveDurationUnit
.It also changes the types of
rate_limt_per_user
,max_age
andafk_timeout
toDuration
, using the new serializers.ArchiveDuration
now also usesDuration
as the backing value.