PolymorphicModuleBuilder

class PolymorphicModuleBuilder<in Base : Any>

A builder which registers all its content for polymorphic serialization in the scope of the base class. If baseSerializer is present, registers it as a serializer for baseClass (which will be used if base class is serializable). Subclasses and its serializers can be added with subclass builder function.

To obtain an instance of this builder, use SerializersModuleBuilder.polymorphic DSL function.

Functions

Link copied to clipboard
fun default(defaultSerializerProvider: (className: String?) -> DeserializationStrategy<out Base>?)

Adds a default deserializers provider associated with the given baseClass to the resulting module. defaultSerializerProvider is invoked when no polymorphic serializers associated with the className were found. className could be null for formats that support nullable class discriminators (currently only Json with JsonBuilder.useArrayPolymorphism set to false)

Link copied to clipboard
fun defaultDeserializer(defaultDeserializerProvider: (className: String?) -> DeserializationStrategy<out Base>?)

Adds a default serializers provider associated with the given baseClass to the resulting module. defaultDeserializerProvider is invoked when no polymorphic serializers associated with the className were found. className could be null for formats that support nullable class discriminators (currently only Json with JsonBuilder.useArrayPolymorphism set to false)

Link copied to clipboard
fun <T : Base> subclass(subclass: KClass<T>, serializer: KSerializer<T>)

Registers a subclass in the resulting module under the base class.

Properties

Link copied to clipboard
val baseClass: KClass<Base>
Link copied to clipboard
val baseSerializer: KSerializer<Base>? = null
Link copied to clipboard
var defaultDeserializerProvider: (String?) -> DeserializationStrategy<out Base>?? = null
Link copied to clipboard
var defaultSerializerProvider: (Base) -> SerializationStrategy<Base>?? = null
Link copied to clipboard
val subclasses: MutableList<Pair<KClass<out Base>, KSerializer<out Base>>>

Extensions

Link copied to clipboard
inline fun <Base : Any, T : Base> PolymorphicModuleBuilder<Base>.subclass(serializer: KSerializer<T>)

Registers a subclass in the resulting module under the base class.

inline fun <Base : Any, T : Base> PolymorphicModuleBuilder<Base>.subclass(clazz: KClass<T>)

Registers a serializer for class T in the resulting module under the base class.