Skip to content
Permalink
Browse files

Add KotlinxSerializer register() to use reified generics to set mapper

  • Loading branch information...
sommd authored and e5l committed Oct 16, 2018
1 parent 918a74a commit 224e00be1d634ee47cf7c93cd2ab672f4aa09064
@@ -20,6 +20,13 @@ class KotlinxSerializer : JsonSerializer {
mappers[type as KClass<Any>] = serializer as KSerializer<Any>
}

/**
* Set the mapping from [T] to it's [KSerializer].
*/
inline fun <reified T : Any> register() {
setMapper(T::class, T::class.serializer())
}

private fun getMapper(type: KClass<*>): KSerializer<Any> {
return mappers[type] ?: throw UnsupportedOperationException("No mapping set for $type")
}

0 comments on commit 224e00b

Please sign in to comment.
You can’t perform that action at this time.