
commonMain.kotlinx.serialization.Serializers.kt Maven / Gradle / Ivy
/*
* Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
@file:Suppress("DEPRECATION_ERROR", "UNCHECKED_CAST")
@file:JvmMultifileClass
@file:JvmName("SerializersKt")
package kotlinx.serialization
import kotlinx.serialization.builtins.*
import kotlinx.serialization.builtins.MapEntrySerializer
import kotlinx.serialization.builtins.TripleSerializer
import kotlinx.serialization.builtins.PairSerializer
import kotlinx.serialization.internal.*
import kotlin.jvm.*
import kotlin.reflect.*
/**
* Creates a serializer for the provided reified type [T] with support of user-defined generic classes.
* This method is a reified version of `serializer(KType)`
*
* Example of usage:
* ```
* val map = mapOf(1 to listOf(listOf("1")))
* json.encodeToString(serializer(), map)
* ```
*/
public inline fun serializer(): KSerializer {
return serializer(typeOf()).cast()
}
/**
* Creates a serializer for the given [type] with support of user-defined generic classes.
* [type] argument can be obtained with experimental [typeOf] method.
*
* Example of usage:
* ```
* val map = mapOf(1 to listOf(listOf("1")))
* val serializer = serializer(typeOf
© 2015 - 2025 Weber Informatics LLC | Privacy Policy