MetaSerializable
The meta-annotation for adding Serializable behaviour to user-defined annotations.
Applying MetaSerializable to the annotation class A
instructs the serialization plugin to treat annotation A as Serializable. In addition, all annotations marked with MetaSerializable are saved in the generated SerialDescriptor as if they are annotated with SerialInfo.
@MetaSerializable
@Target(AnnotationTarget.CLASS)
annotation class MySerializable(val data: String)
@MySerializable("some_data")
class MyData(val myData: AnotherData, val intProperty: Int, ...)
val serializer = MyData.serializer()
serializer.descriptor.annotations.filterIsInstance<MySerializable>().first().data // <- returns "some_data"
Content copied to clipboard