Class 'EmptyMap' is not registered for polymorphic serialization in the scope of 'Map'.
To be registered automatically, class 'EmptyMap' has to be '@Serializable', and the base class 'Map' has to be sealed and '@Serializable'.
a
asdf asdf
07/20/2023, 9:11 PM
Can you send the code where this is happening? `Map`s already have a builtin
MapSerializer
, so it would be strange to serialize them polymorphically
t
Tianyu Zhu
07/20/2023, 9:13 PM
I've looked into it a bit more...
1. It works when I just write
Json.encodeToString(mapOf())
2. It doesn't work when I try to serialize it with ktor client...
3. After some debugging, it seems like ktor is not finding the
LinkedHashMapSerializer
. It's instead trying to find a
PolymorphicSerializer
...
Tianyu Zhu
07/20/2023, 9:14 PM
And it's not just EmptyMap that doesn't work, I can't even serialize a LinkedHashMap using Ktor...
g
glureau
07/21/2023, 12:00 PM
Try to specify the generic type
Json.encodeToString<Map<Xxx>>(myMap)
glureau
07/21/2023, 12:01 PM
If you don't specify the generic type, it's automatically inferred but it will depend on how serializers are setup by default. In you log you said it doesn't find LinkedHashMapSerializer, so I presume your parameter is a LinkedHashMap, and it's possible it's not explicitely serialized with MapSerializer.