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.

Link copied to clipboard

Registers the child serializers for the sealed type T in the resulting module under the base class. Please note that type T has to be sealed and have a standard serializer, if not a runtime error will be thrown at registration time. If one of T's subclasses is a sealed serializable class on its own, its subclasses are registered recursively as well. If one of T's subclasses is an open polymorphic class an IllegalArgumentException is thrown.

Registers the child serializers for the sealed type T in the resulting module under the base class. Please note that type T has to be sealed and have a standard serializer, if not a runtime error will be thrown at registration time. If one of T's subclasses is a sealed serializable class on its own, its subclasses are registered recursively as well. If one of T's subclasses is an open polymorphic class an IllegalArgumentException is thrown.

Link copied to clipboard

Registers the child serializers for the sealed class T in the resulting module under the base class.