Hi, in a Kotlin MPP, is there a clean way of seria...
# serialization
m
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
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
Understood, thanks for the clarification
s
There's a not so clean way to do it with a custom serializer.
s
Recommended way to go is to convert your map to
JsonObject
.