Does anyone have any suggestions for dealing with ...
# kotlinx-datetime
e
Does anyone have any suggestions for dealing with errors like this? > org.apache.fury.exception.InsecureException: class kotlin.time.InstantSerialized is not registered... Basically, a serialization library wants me to register
InstantSerialized::class.java
because I use
kotlin.time.Instant
in a data class but I can't because
InstantSerialized
is private. I did not have this problem with
kotlinx-datetime
.
d
I don't know what exactly is going on, but here is some context:
InstantSerialized
is used when
Instant
gets serialized by Java serialization.
kotlinx.datetime.Instant
didn't implement
java.io.Serializable
, so it was impossible to serialize it directly in Java, you had to add some adapter (like this one: https://github.com/Kotlin/kotlinx-datetime/issues/143#issuecomment-975380754). Somehow, adding Java serialization support to
Instant
broke your use case. Did you use such an adapter before, with
kotlinx-datetime
? If so, it may be necessary to get back to doing that.
e
>
kotlinx.datetime.Instant
didn't implement
java.io.Serializable
... What do you call this, then?
d
I call this using
kotlinx.serialization
.
e
What's the difference, and its consequences?
d
kotlinx.serialization
is a Kotlin-specific serialization mechanism that works on the JVM + JS + Native + Wasm.
java.io.Serializable
is the standard serialization mechanism available in all JVM languages, but only on them. These two mechanisms are completely separate and incompatible. We recommend using
kotlinx.serialization
, as it solves some of the pitfalls of Java serialization, but Java serialization is still occasionally necessary even in Kotlin code when a language-agnostic JVM framework or library demands it.