Skip to content

Commit

Permalink
Add KotlinxSerializer.register() with explicit KSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
sommd authored and e5l committed Oct 18, 2018
1 parent 1a2f90c commit cf54684
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -43,11 +43,16 @@ class KotlinxSerializer : JsonSerializer {
mappers[type as KClass<Any>] = serializer as KSerializer<Any>
}

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

/**
* Set the mapping from [T] to it's [KSerializer].
* Set the mapping from [T] to it's [KSerializer]. This method only works for non-parameterized types.
*/
inline fun <reified T : Any> register() {
setMapper(T::class, T::class.serializer())
register(T::class.serializer())
}

private fun getMapper(type: KClass<*>): KSerializer<Any> {
Expand Down

0 comments on commit cf54684

Please sign in to comment.