Kotlin / kotlinx.serialization

Kotlin multiplatform / multi-format serialization
Apache License 2.0
5.4k stars 621 forks source link

Don't require @Serializable annotation for children of @Serializable sealed class #909

Open SerVB opened 4 years ago

SerVB commented 4 years ago

What is your use-case and why do you need this feature? I have sealed classes for polymorphic serialization. Now I have to write @Serializable for all the children which is monotonous and takes many lines of code, making it less readable.

Describe the solution you'd like I think if a user marked a sealed class as @Serializable, all the children should become serializable automatically. As the plugin already can find all the children to add them to polymorphic serialization variants, it can also mark those children.

sandwwraith commented 4 years ago

Note: there should be opt-out mechanism if one do not want particular child of sealed class to be serializable.

SerVB commented 4 years ago

Related: #925.

there should be opt-out mechanism if one do not want particular child of sealed class to be serializable

It seems that currently if a child is not serializable, polymorphic serialization won't work at all. So maybe initially such mechanism is not needed...

sandwwraith commented 4 years ago

Well, #925 is a bug that should be fixed)