TomlClassDiscriminator

@InheritableSerialInfo
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class TomlClassDiscriminator(val discriminator: String)(source)

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"))

will produce:

[element]
class = "package.Literal"
string = "Hello"

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.

Properties

Link copied to clipboard