From 79ed26e9bbfbe7174a913fc7c96e798a50454bb2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 12 Aug 2020 12:55:04 +0600 Subject: [PATCH 1/3] start 0.3.1 --- CHANGELOG.md | 2 ++ build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6da894..1950e5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ * 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 + ## 0.2.0 * `Kotlin`: `1.3.61` -> `1.3.70` diff --git a/build.gradle b/build.gradle index 023da18..1edf918 100644 --- a/build.gradle +++ b/build.gradle @@ -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" From f9d5a583dddc483aff9e96fbf364dd8b9a604132 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 12 Aug 2020 12:56:12 +0600 Subject: [PATCH 2/3] update kotlin version --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1950e5e..9fc8b83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ ### 0.3.1 +* `Kotlin`: `1.3.71` -> `1.3.72` + ## 0.2.0 * `Kotlin`: `1.3.61` -> `1.3.70` diff --git a/gradle.properties b/gradle.properties index 1de97a5..84eaf39 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 From 99cc49d7581d7ac46e54ded24c2129bb7a629120 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 12 Aug 2020 13:58:00 +0600 Subject: [PATCH 3/3] optionalContextual --- CHANGELOG.md | 1 + .../sdi/utils/OptionalContextualIncluding.kt | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/OptionalContextualIncluding.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fc8b83..4c47d4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### 0.3.1 * `Kotlin`: `1.3.71` -> `1.3.72` +* Add `SerializersModuleBuilder#optionalContextual` for more comfortable usage of `contextual` ## 0.2.0 diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/OptionalContextualIncluding.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/OptionalContextualIncluding.kt new file mode 100644 index 0000000..085aa46 --- /dev/null +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/OptionalContextualIncluding.kt @@ -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 SerializersModuleBuilder.optionalContextual( + kClass: KClass, kSerializer: KSerializer +) = try { + contextual(kClass, kSerializer) + true +} catch (e: SerializerAlreadyRegisteredException) { + false +} + +@InternalSerializationApi +inline fun SerializersModuleBuilder.optionalContextual( + kSerializer: KSerializer +) = optionalContextual(T::class, kSerializer) \ No newline at end of file