Serialization of value class kotlin.time.Duration does not work
See original GitHub issueTrying to use the value class Duration
with kotlin 1.5 and serialization 1.2 states
kotlinx.serialization.SerializationException: Serializer for class 'Duration' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
My expectation is that value classes would “simply work”. The Duration
class is not owned by me but the kotlin platform so attaching a @Serializable
annotation is not possible.
To Reproduce
@Serializable
data class MyObject(
val time: Duration = Duration.ZERO
)
Expected behavior Serialize.
Environment
- Kotlin version: 1.5.0
- Library version: 1.2.0
- Kotlin platforms: JVM
- Gradle version: 7.x
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:12 (6 by maintainers)
Top Results From Across the Web
For serial name Duration there already exist ...
Duration, I had my own custom serializer. So far so good. Now I want to update the kotlinx serialization libraries to 1.4.0, which...
Read more >How to serialize Duration? - Support - Kotlin Discussions
I know how to write a serializer, so I'm really asking: how to round trip a Duration with some other primitive value(s). Does...
Read more >Duration | Android Developers
This class models a quantity or amount of time in terms of seconds and nanoseconds. It can be accessed using other duration-based units,...
Read more >Android Data Serialization Tutorial with the Kotlin Serialization ...
This signals a decoder has no more properties to read. Now that the serializer is complete, it's time to wire it with the...
Read more >Language Guide (proto3) | Protocol Buffers - Google Developers
It will be serialized to the wire unless it is the default value. ... can also cause issues for JSON serialization) of your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for reminder, we’ll update the priority
Edit:
Wrong alarm. I was using java time. Keeping original post below the line.
are we sure if this is deployed? On my end, Duration is not still serializable by default.