kotlinx-serialization / kotlinx.serialization.modules / PolymorphicModuleBuilder / default

default

(common, js, jvm, native) fun default(defaultSerializerProvider: (className: String) -> DeserializationStrategy<out Base>?): Unit

Registers serializer provider that will be invoked if no polymorphic serializer is present. defaultSerializerProvider can be stateful and lookup a serializer for the missing type dynamically.

Typically, if the class is not registered in advance, it is not possible to know the structure of the unknown type and have a precise serializer, so the default serializer has limited capabilities. To have a structural access to the unknown data, it is recommended to use JsonTransformingSerializer or JsonParametricSerializer classes.