SerializersModuleBuilder

A builder class for SerializersModule DSL. To create an instance of builder, use SerializersModule factory function.

Functions

Link copied to clipboard
open override fun <T : Any> contextual(kClass: KClass<T>, provider: (typeArgumentsSerializers: List<KSerializer<*>>) -> KSerializer<*>)

Registers provider associated with given generic kClass for contextual serialization. When a serializer is requested from a module, provider is being called with type arguments serializers of the particular kClass usage.

open override fun <T : Any> contextual(kClass: KClass<T>, serializer: KSerializer<T>)

Adds serializer associated with given kClass for contextual serialization. If kClass has generic type parameters, consider registering provider instead.

Link copied to clipboard
inline fun <T : Any> SerializersModuleBuilder.contextual(serializer: KSerializer<T>)

Adds serializer associated with given type T for contextual serialization. Throws SerializationException if a module already has serializer associated with the given type. To overwrite an already registered serializer, SerializersModule.overwriteWith can be used.

Link copied to clipboard

Copies the content of module module into the current builder.

Link copied to clipboard
open override fun <Base : Any, Sub : Base> polymorphic(baseClass: KClass<Base>, actualClass: KClass<Sub>, actualSerializer: KSerializer<Sub>)

Adds serializer associated with given actualClass in the scope of baseClass for polymorphic serialization. Throws SerializationException if a module already has serializer associated with a actualClass. To overwrite an already registered serializer, SerializersModule.overwriteWith can be used.

Link copied to clipboard
inline fun <Base : Any> SerializersModuleBuilder.polymorphic(baseClass: KClass<Base>, baseSerializer: KSerializer<Base>? = null, builderAction: PolymorphicModuleBuilder<Base>.() -> Unit = {})

Creates a builder to register subclasses of a given baseClass for polymorphic serialization. If baseSerializer is not null, registers it as a serializer for baseClass, which is useful if the base class is serializable itself. To register subclasses, PolymorphicModuleBuilder.subclass builder function can be used.

Link copied to clipboard
open override fun <Base : Any> polymorphicDefaultDeserializer(baseClass: KClass<Base>, defaultDeserializerProvider: (className: String?) -> DeserializationStrategy<Base>?)

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

Link copied to clipboard
open override fun <Base : Any> polymorphicDefaultSerializer(baseClass: KClass<Base>, defaultSerializerProvider: (value: Base) -> SerializationStrategy<Base>?)

Adds a default serializers provider associated with the given baseClass to the resulting module. defaultSerializerProvider is invoked when no polymorphic serializers for value in the scope of baseClass were found.