CLOVIS
11/26/2025, 8:30 PMserializer(foo: KType) .
I have this test code:
test("Access a serializer that doesn't exist on all platforms") {
check(serializerOrNull(typeOf<Foo>()) == null) { "The class Foo is not serializable, this code shouldn't find a serializer" }
}
test("Access a serializer that exists on all platforms") {
check(serializerOrNull(typeOf<Profile>()) != null) { "The class Profile is serializable, this code should find a serializer" }
}
test("Access a serializer for ObjectId on all platforms") {
check(serializerOrNull(typeOf<ObjectId>()) != null) { "The class ObjectId is serializable, this code should find a serializer" }
}
test("Access a serializer for Foo2 on all platforms") {
check(serializerOrNull(typeOf<Foo2>()) != null) { "The class Foo2 is serializable, this code should find a serializer" }
}
with the types:
@Serializable
data class Profile(
val name: String,
val age: Int,
)
class Foo(val a: Int)
and in another module, that has the Serialization plugin:
@Serializable(with = ObjectId.Serializer::class)
class ObjectId : Comparable<ObjectId> {
class Serializer : KSerializer<ObjectId> { … }
}
@Serializable
class Foo2(val a: Int)
and I get the result:
• Serializer of `Foo`: OK on all platforms (returns null)
• Serializer of Profile : OK on all platforms (returns non-null)
• Serializer of ObjectId : Fails on non-JVM platforms (returns null)
• Serializer of `Foo2`: OK on all platforms (returns non-null)
So I guess that means serializer(KType) cannot find classes with a custom serializer? That's very unfortunate.CLOVIS
11/26/2025, 8:35 PM@ObjectId uses a plain old @Serializable without a with , then serializer(KType) finds it 🤦♂️CLOVIS
11/26/2025, 9:16 PMCLOVIS
11/26/2025, 9:22 PMCLOVIS
11/28/2025, 6:41 PM