PolymorphicModuleBuilder

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 defaultDeserializer(defaultDeserializerProvider: (className: String?) -> DeserializationStrategy<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.

Link copied to clipboard

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

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

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