Also support intrinsification for SerializersModule.serializer<T>()

method that fallbacks to module.getContextual().
This commit is contained in:
Leonid Startsev
2022-08-25 17:38:43 +02:00
committed by Space
parent a59f5f407b
commit aac9a06474
14 changed files with 844 additions and 117 deletions
@@ -0,0 +1,32 @@
// CURIOUS_ABOUT: test, getSer
// WITH_STDLIB
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.modules.*
@Serializable
class Simple(val firstName: String, val lastName: String)
class NoSer
class NoSerGeneric<T>
val module = SerializersModule {}
inline fun <reified T: Any> getSer(module: SerializersModule): KSerializer<T> {
return module.serializer()
}
fun test() {
module.serializer<Simple>()
module.serializer<NoSer>()
module.serializer<List<Simple>>()
module.serializer<List<NoSer>>()
getSer<Simple>(module)
getSer<NoSer>(module)
getSer<NoSerGeneric<Simple>>(module)
getSer<NoSerGeneric<NoSer>>(module)
}