Hoping someone has an answer for this one. I have ...
# serialization
s
Hoping someone has an answer for this one. I have a use case building a Map<String, JsonElement> where the values in the map are all JsonPrimitve from various basic types like String, Int, Float, etc. With a map name of jsonRow, using this:
Copy code
val json = Json { encodeDefaults = true }
val jsonString = json.encodeToString(JsonObject(jsonRow))
works fine in debug producing correct JSON. But release minified build gets this exception in the encodeToString call:
Copy code
Serializer for class 'x' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
    k9.k: Serializer for class 'x' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
What should I change to correct this? I have proguard rules set up for explicit @Serializable data classes and they work fine. But I have no rule(s) for this "dynamic" encode use case and am not sure what "class 'x'" is so don't know what rule to try. Is it saying that it can't find the serializer for Map (class 'x' minified), even though that is the explicit type required by the JsonObject constructor? Any help/tips are appreciated, my searches for something like this are not finding good hits 🙂 This is serialization 1.3.1 and kotlin 1.6.10.
e
Copy code
json.encodeToString(JsonObject.serializer(), JsonObject(jsonRow))
s
That works, thanks!