Skip to content

Passing serializers dynamically #2992

Open
@arkivanov

Description

@arkivanov

It would be really useful if we could specify serializers for non-serializable properties at runtime, similarly to how we specify serializers for generic properties. An imaginatory API could look like this.

The code from a library:

interface Args

@Serializable
class ArgsHolder(@DynamicallySerializable val args: Args)

Then the library consumer's (client) code:

@Serializable
class ArgsA(val data: String) : Args

@Serializable
class ArgsB(val data: String) : Args

val argsSerializer : KSerializer<Args> = ... // Created dynamically at runtime

val serializer = ArgsHolder.serializer(ArgsSerializer)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions