Hey there, why don't custom serializers come have ...
# serialization
a
Hey there, why don't custom serializers come have the Companion.serializer() method?? I have
Copy code
@Serializable(with = SignedIn.Companion::class)
interface SignedIn : Session {

    @Serializer(forClass = SignedIn::class)
    companion object : KSerializer<SignedIn> {
        override val descriptor: SerialDescriptor = buildClassSerialDescriptor("session.signedin")

        override fun deserialize(decoder: Decoder): SignedIn {
            TODO("Not yet implemented")
        }

        override fun serialize(encoder: Encoder, value: SignedIn) {
            TODO()
        }
    }
}
And my test are as follows
Copy code
val session : SignedIn = getSession()
println(Json.encodeToString(session)) // fails with: Serializer for class 'SignedIn' is not found.
println(Json.encodeToString(SignedIn,session)) // passes
println(Json.encodeToString(SignedIn.serializer(),session)) // won't compile
Why can't the compiler find the custom serializer??
e
https://github.com/Kotlin/kotlinx.serialization/issues/1386 it should be in Kotlin 1.6.10 and later
a
Thank you
a
hey
there?
a
I upgrade to 1.6.10, and I a still experiencing the same
e
works fine for me. consider filing a bug with a reproducible test case
although hmm, I think I see a potential cause. works fine on
class
, but not on
interface