Adam S
06/04/2022, 11:30 AM@Serializable
, on the field, for a whole file, in multiple ways with a SerializersModules, and there's also reflection.
Is the order of priority defined somewhere?
I'm asking because I want to see how to override a serializer that's defined on a class with @Serializable(with = ...)
, and it's not clear in which order serializers are considered and selected.ephemient
06/04/2022, 11:38 AMSerializersModule
can only affect @Contextual
and @Polymorphic
serialization (additionally, @file:UseContextualSerializers
is @Contextual
on everything). @Serializable(with = )
on a property overrides @file:UseSerializers
overrides the type's own serializer.ephemient
06/04/2022, 11:38 AMSerializers from this list have higher priority than default, but lesser priority than serializers defined on the property itself, such as Serializable (with=...) or Contextual.
ephemient
06/04/2022, 11:42 AMserializer(KType)
and similar, that doesn't have access to SerializersModule
, so there's only one thing it can possibly do. SerializersModule.serializer(KType)
is documented to look up from the module first with fallback: https://kotlin.github.io/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/serializer.html