Toml Class Discriminator
Changes the key of the class discriminator of a specific type hierarchy.
@Serializable
@TomlClassDiscriminator("class")
sealed class Element
@Serializable
data class Literal(
val string: String
) : Element()
@Serializable
data class Data(
val element: Element
)
Data(Literal("Hello"))Content copied to clipboard
will produce:
[element]
class = "package.Literal"
string = "Hello"Content copied to clipboard
Again, this annotation will affect the whole type hierarchy, so any subclass will use the same discriminator. It is not possible to define different discriminators in different parts of the hierarchy.
To change the default discriminator, please refer to Toml factory function and TomlConfigBuilder.classDiscriminator.