Merge branch '0.3.1' of InsanusMokrassar/SDI into master

This commit is contained in:
Aleksei Ovsiannikov 2020-08-12 08:00:27 +00:00 committed by Gogs
commit 1fc3dba66a
4 changed files with 28 additions and 2 deletions

View File

@ -9,6 +9,11 @@
* Now it will correctly resolve objects which was not previously registered
* By default, for modules loading will be used context from `Json`, passed as receiver
### 0.3.1
* `Kotlin`: `1.3.71` -> `1.3.72`
* Add `SerializersModuleBuilder#optionalContextual` for more comfortable usage of `contextual`
## 0.2.0
* `Kotlin`: `1.3.61` -> `1.3.70`

View File

@ -17,7 +17,7 @@ plugins {
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
}
project.version = "0.3.0"
project.version = "0.3.1"
project.group = "com.insanusmokrassar"
apply from: "publish.gradle"

View File

@ -1,5 +1,5 @@
kotlin.code.style=official
kotlin_version=1.3.71
kotlin_version=1.3.72
kotlin_serialisation_runtime_version=0.20.0
gradle_bintray_plugin_version=1.8.4

View File

@ -0,0 +1,21 @@
package com.insanusmokrassar.sdi.utils
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.modules.*
import kotlin.reflect.KClass
@InternalSerializationApi
fun <T : Any> SerializersModuleBuilder.optionalContextual(
kClass: KClass<T>, kSerializer: KSerializer<T>
) = try {
contextual(kClass, kSerializer)
true
} catch (e: SerializerAlreadyRegisteredException) {
false
}
@InternalSerializationApi
inline fun <reified T : Any> SerializersModuleBuilder.optionalContextual(
kSerializer: KSerializer<T>
) = optionalContextual(T::class, kSerializer)