Hello, I want to decode the string `json.decodeFro...
# serialization
d
Hello, I want to decode the string
json.decodeFromString<Map<String, @Serializable(with = AnyValueSerializer::class) Any?>>(string)
Serializer
Copy code
object AnyValueSerializer : KSerializer<Any?> {
    private val delegateSerializer = JsonElement.serializer()
    override val descriptor = delegateSerializer.descriptor

    override fun serialize(encoder: Encoder, value: Any?) {
        encoder.encodeSerializableValue(delegateSerializer, value.toJsonElement())
    }

    override fun deserialize(decoder: Decoder): Any? {
        val jsonPrimitive = decoder.decodeSerializableValue(JsonPrimitive.serializer())
        return jsonPrimitive.toAnyValue()
    }
}
It is works correct on Android, bot on iOS I get the exception. I dunnot expect any Enum or smth similar, only primitives. string that I want to decode
{ "userId": 30123 }
e
does the non-reified version work?
Copy code
json.decodeFromString(MapSerializer(String.serializer(), AnyValueSerializer), string)
d
Yes, it works ty @ephemient K