m

    Max Raskin

    2 years ago
    Hi, in a Kotlin MPP, is there a clean way of serializing a Map<String, Any> to a JSON string? I've tried doing it using kotlinx.serialization but it seems to support only classes annotated with @Serializable, am I missing something? Thanks 🙂
    c

    Casey Brooks

    2 years ago
    Probably not. That would require serializing
    Any
    to JSON, which is either: 1) always an empty map, since the known
    Any
    type has no properties, or 2) requires reflection to look up the members of the actual type and recursively serialize those. But reflection is not fully supported in MPP yet, so #2 is not possible, currently.
    m

    Max Raskin

    2 years ago
    Understood, thanks for the clarification
    s

    Sam

    2 years ago
    There's a not so clean way to do it with a custom serializer.
    s

    sandwwraith

    2 years ago
    Recommended way to go is to convert your map to
    JsonObject
    .