Deriving external serializer for another Kotlin class
I have a third party class that is generated as the following
data class Example (
property: String
)
data class AnotherExample (
property: Example
)
I want to serialize the class AnotherExample so I am doing it as below
@OptIn(ExperimentalSerializationApi::class)
@Serializer(forClass = AnotherExample::class)
object AnotherExampleSerializer
However, during compilation, I am getting the error Serializer for element of type Example has not been found. Going by this, I need to create another custom serializer but this time for Example, which I have done the same way as I did for AnotherExample class. Problem is, how do I link the two given they are both 3rd party classes?
There is currently no such feature. Perhaps if you use @file:UseSerializers annotation, it can be picked by the plugin.
It is also possible to use a type alias: typealias MyExample=@Serializable(YourSerializer::class) Example
Tried both the above suggestions but none of them seem to work unfortunately.