question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serialization of value class kotlin.time.Duration does not work

See original GitHub issue

Trying 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
sandwwraithcommented, Feb 21, 2022

Thanks for reminder, we’ll update the priority

3reactions
gunesscommented, Oct 19, 2022

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.

version.kotlinx.serialization=1.4.1
version.kotlin=1.7.20
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found