Thread
#serialization
    v

    Vampire

    2 months ago
    I want to port the custom serializer at https://github.com/Vampire/setup-wsl/blob/master/buildSrc/src/main/kotlin/net/kautler/dao/GitHubAction.kt#L73 that still runs on 0.20.0 to 1.3.x. I there have used
    override val descriptor = SerialDescriptor("...", CONTEXTUAL)
    for the
    KSerializer
    . How would I port that to 1.3.x as the function does not expect a kind anymore?
    s

    Sebastian Schuberth

    2 months ago
    Would using the (experimental) @Serializerannotation maybe work?
    Ah, sorry, just saw you're actually already using it at https://github.com/Vampire/setup-wsl/blob/bcd134a8857d9afc02db9cc3fa981a30e231ab61/buildSrc/src/main/kotlin/net/kautler/dao/GitHubAction.kt#L67. I thought specifying the
    descriptor
    is then not required anymore.
    v

    Vampire

    2 months ago
    Hm, not at my box right now, but I think if I remove the descriptor it complains that it is missing and if I make the class abstract it cannot instantiate it.
    s

    Sebastian Schuberth

    2 months ago
    v

    Vampire

    2 months ago
    Your example does not match, because it is not about a generic type. For a generic type like in my case you do not need an
    object
    , but a class with constructor and also a provided descriptor. And additionally the serializer is contextual. I needed quite some time and comments to get it working properly back then with 0.20.0.
    Hm, I found that it works if I use
    @InternalSerializationApi
    override val descriptor = buildSerialDescriptor("...", CONTEXTUAL)
    but I don't like the internal serialization api being used. It's documentation says that it should not be used, and if necessary issues filed. So is there another way to get a serial descriptor with
    CONTEXTUAL
    kind?
    Hm, I found that it works if I use
    @InternalSerializationApi
    override val descriptor = buildSerialDescriptor("...", CONTEXTUAL)
    but I don't like the internal serialization api being used. It's documentation says that it should not be used, and if necessary issues filed. So is there another way to get a serial descriptor with
    CONTEXTUAL
    kind?
    Anyone?
    Emil Kantis

    Emil Kantis

    1 month ago
    Wouldn't a Map serial descriptor be appropriate in this case?
    mapSerialDescriptor<String, Output>()
    v

    Vampire

    1 month ago
    No, it must be a contextual descriptor or the processes is not done contextually