https://kotlinlang.org logo
#serialization
Title
# serialization
p

Piotr Krzemiński

12/03/2023, 9:48 PM
I'm calling
encodeToString
with an object of type
Map<String, Boolean>
. I now pass
Copy code
MapSerializer(String.serializer(), Boolean.serializer())
as the first argument to make it work, but I'm fairly sure there's a way for the compiler to infer it. Is there (without creating a wrapper type annotated with
@Serializable
)? 🙂
k

kevin.cianfarini

12/03/2023, 9:51 PM
There's the
encodeToString
which takes a reified type parameter and then uses reflection to look up the type's serializers. This comes at a performance penalty though.
p

Piotr Krzemiński

12/03/2023, 9:54 PM
thanks!
e

ephemient

12/03/2023, 11:25 PM
there's no penalty anymore as it is now intrinsified, https://github.com/Kotlin/kotlinx.serialization/issues/1348
🎉 2
k

kevin.cianfarini

12/09/2023, 3:11 PM
Neat! I had no idea.