From 1b8756203591fd5636680a5f72cabdd30e4df75f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 11:14:41 +0600 Subject: [PATCH 01/11] started 0.1.2 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d53ef0..a45fcc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # SDI changelogs +## 0.1.2 + ## 0.1.1 * Added opportunity to create objects inside of config: From ea29a801fd958bc397d4e693e52f726f79d15b21 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 12:56:04 +0600 Subject: [PATCH 02/11] decrease number of expected functions --- build.gradle | 2 +- .../insanusmokrassar/sdi/ModuleSerializer.kt | 7 ++-- .../sdi/utils/DependencyResolver.kt | 5 +-- .../sdi/utils/JsonAdaptations.kt | 36 ++++++++++--------- .../insanusmokrassar/sdi/utils/TypesHelper.kt | 22 ++++++------ .../com/insanusmokrassar/sdi/ListTest.kt | 3 +- .../sdi/SimpleCustomObjectTest.kt | 3 +- .../com/insanusmokrassar/sdi/SimpleTest.kt | 3 +- .../sdi/utils/currentSupertypes.kt | 7 ---- .../utils/resolveSerializerByPackageName.kt | 7 ---- 10 files changed, 42 insertions(+), 53 deletions(-) delete mode 100644 src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/currentSupertypes.kt diff --git a/build.gradle b/build.gradle index 0134720..7d8d339 100644 --- a/build.gradle +++ b/build.gradle @@ -36,7 +36,7 @@ kotlin { commonMain { dependencies { implementation kotlin('stdlib') - api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" + api kotlin('reflect') api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version" } } diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt index 50516de..267f021 100644 --- a/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt @@ -1,11 +1,10 @@ package com.insanusmokrassar.sdi -import com.insanusmokrassar.sdi.utils.* +import com.insanusmokrassar.sdi.utils.createModuleBasedOnConfigRoot import kotlinx.serialization.* -import kotlinx.serialization.internal.* +import kotlinx.serialization.internal.HashMapSerializer +import kotlinx.serialization.internal.StringSerializer import kotlinx.serialization.json.* -import kotlinx.serialization.modules.* -import kotlin.reflect.KClass @ImplicitReflectionSerializer @Serializable(ModuleSerializer::class) diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/DependencyResolver.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/DependencyResolver.kt index 488d650..5ccaf93 100644 --- a/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/DependencyResolver.kt +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/DependencyResolver.kt @@ -2,7 +2,8 @@ package com.insanusmokrassar.sdi.utils import kotlinx.serialization.* import kotlinx.serialization.json.* -import kotlinx.serialization.modules.* +import kotlinx.serialization.modules.SerializerAlreadyRegisteredException +import kotlinx.serialization.modules.SerializersModuleBuilder import kotlin.reflect.KClass @ImplicitReflectionSerializer @@ -13,7 +14,7 @@ internal class DependencyResolver( private val dependencyGetter: (String) -> Any ) : KSerializer { private val originalSerializer: KSerializer = try { - resolveSerializerByKClass(kClass) + kClass.serializer() } catch (e: Exception) { PolymorphicSerializer(kClass) } diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/JsonAdaptations.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/JsonAdaptations.kt index 7a065b4..2d57c3d 100644 --- a/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/JsonAdaptations.kt +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/JsonAdaptations.kt @@ -1,8 +1,9 @@ package com.insanusmokrassar.sdi.utils -import kotlinx.serialization.* +import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.json.* -import kotlinx.serialization.modules.* +import kotlinx.serialization.modules.SerializerAlreadyRegisteredException +import kotlinx.serialization.modules.SerializersModule private typealias PackageOrOtherDependencyNamePair = Pair @@ -63,25 +64,26 @@ internal fun createModuleBasedOnConfigRoot(jsonObject: JsonObject): Json { key to packageName }.toMap() - return Json( - configuration = JsonConfiguration(useArrayPolymorphism = true), - context = SerializersModule { - keysToPackages.values.forEach { - val kclass = resolveKClassByPackageName(it) + val context = SerializersModule { + keysToPackages.values.forEach { + val kclass = resolveKClassByPackageName(it) - try { - DependencyResolver( - this, - kclass, - { jsonStringFormat } - ) { - caches.getValue(it).invoke() - } - } catch (e: SerializerAlreadyRegisteredException) { - // here we are thinking that already registered + try { + DependencyResolver( + this, + kclass, + { jsonStringFormat } + ) { + caches.getValue(it).invoke() } + } catch (e: SerializerAlreadyRegisteredException) { + // here we are thinking that already registered } } + } + return Json( + configuration = JsonConfiguration(useArrayPolymorphism = true), + context = context ).also { jsonStringFormat = it } diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/TypesHelper.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/TypesHelper.kt index 1dccd38..8fe8c03 100644 --- a/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/TypesHelper.kt +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/TypesHelper.kt @@ -1,24 +1,22 @@ package com.insanusmokrassar.sdi.utils -import kotlinx.serialization.ImplicitReflectionSerializer -import kotlinx.serialization.KSerializer +import kotlinx.serialization.* import kotlin.reflect.KClass -import kotlin.reflect.KType - -@ImplicitReflectionSerializer -expect fun resolveSerializerByPackageName(packageName: String): KSerializer<*> - -@ImplicitReflectionSerializer -expect fun resolveSerializerByKClass(kClass: KClass): KSerializer expect fun resolveKClassByPackageName(packageName: String): KClass<*> -expect val KClass<*>.currentSupertypes: List +@ImplicitReflectionSerializer +internal fun resolveSerializerByKClass(kClass: KClass): KSerializer = kClass.serializer() -val KClass<*>.allSubclasses: Set> +@ImplicitReflectionSerializer +internal fun resolveSerializerByPackageName(packageName: String): KSerializer<*> = resolveSerializerByKClass( + resolveKClassByPackageName(packageName) +) + +internal val KClass<*>.allSubclasses: Set> get() { val subclasses = mutableSetOf>() - val leftToVisit = currentSupertypes.mapNotNull { it.classifier as? KClass<*> }.toMutableList() + val leftToVisit = supertypes.mapNotNull { it.classifier as? KClass<*> }.toMutableList() while (leftToVisit.isNotEmpty()) { val top = leftToVisit.removeAt(0) if (subclasses.add(top)) { diff --git a/src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt b/src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt index c93983f..62abb6f 100644 --- a/src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt +++ b/src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt @@ -2,7 +2,8 @@ package com.insanusmokrassar.sdi import kotlinx.serialization.* import kotlinx.serialization.json.Json -import kotlin.test.* +import kotlin.test.Test +import kotlin.test.assertEquals interface List_ParentalAPI { val services: List diff --git a/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleCustomObjectTest.kt b/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleCustomObjectTest.kt index 6d76ace..23091e6 100644 --- a/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleCustomObjectTest.kt +++ b/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleCustomObjectTest.kt @@ -2,7 +2,8 @@ package com.insanusmokrassar.sdi import kotlinx.serialization.* import kotlinx.serialization.json.Json -import kotlin.test.* +import kotlin.test.Test +import kotlin.test.assertEquals interface SimpleCustomObject_ControllerAPI { fun showUp() diff --git a/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleTest.kt b/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleTest.kt index 7866ec0..a02fe3a 100644 --- a/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleTest.kt +++ b/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleTest.kt @@ -2,7 +2,8 @@ package com.insanusmokrassar.sdi import kotlinx.serialization.* import kotlinx.serialization.json.Json -import kotlin.test.* +import kotlin.test.Test +import kotlin.test.assertEquals interface Simple_ControllerAPI { fun showUp() diff --git a/src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/currentSupertypes.kt b/src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/currentSupertypes.kt deleted file mode 100644 index b31e1a0..0000000 --- a/src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/currentSupertypes.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.insanusmokrassar.sdi.utils - -import kotlin.reflect.KClass -import kotlin.reflect.KType - -actual val KClass<*>.currentSupertypes: List - get() = this.supertypes diff --git a/src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/resolveSerializerByPackageName.kt b/src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/resolveSerializerByPackageName.kt index 238a50e..0405c8e 100644 --- a/src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/resolveSerializerByPackageName.kt +++ b/src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/resolveSerializerByPackageName.kt @@ -1,12 +1,5 @@ package com.insanusmokrassar.sdi.utils -import kotlinx.serialization.* import kotlin.reflect.KClass -@ImplicitReflectionSerializer -actual fun resolveSerializerByPackageName(packageName: String): KSerializer<*> = Class.forName(packageName).kotlin.serializer() - -@ImplicitReflectionSerializer -actual fun resolveSerializerByKClass(kClass: KClass): KSerializer = kClass.serializer() - actual fun resolveKClassByPackageName(packageName: String): KClass<*> = Class.forName(packageName).kotlin From 25ea1e2a11f9adb0b7b0e61cf3091192f5e74b87 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 12:57:41 +0600 Subject: [PATCH 03/11] now all reflection support methods are internal --- .../kotlin/com/insanusmokrassar/sdi/utils/TypesHelper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/TypesHelper.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/TypesHelper.kt index 8fe8c03..c869c5d 100644 --- a/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/TypesHelper.kt +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/utils/TypesHelper.kt @@ -3,7 +3,7 @@ package com.insanusmokrassar.sdi.utils import kotlinx.serialization.* import kotlin.reflect.KClass -expect fun resolveKClassByPackageName(packageName: String): KClass<*> +internal expect fun resolveKClassByPackageName(packageName: String): KClass<*> @ImplicitReflectionSerializer internal fun resolveSerializerByKClass(kClass: KClass): KSerializer = kClass.serializer() From 369c8e773c113d51b4dbf239f9e41301860d9636 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 12:58:14 +0600 Subject: [PATCH 04/11] fill CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a45fcc5..0a4ef01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.1.2 +* All reflection support methods are internal + ## 0.1.1 * Added opportunity to create objects inside of config: From e6b4912835e0a7122e90edf721ad2918261f8ec1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 13:18:15 +0600 Subject: [PATCH 05/11] rename current actual to resolveKClassByPackageName --- ...veSerializerByPackageName.kt => resolveKClassByPackageName.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/{resolveSerializerByPackageName.kt => resolveKClassByPackageName.kt} (100%) diff --git a/src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/resolveSerializerByPackageName.kt b/src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/resolveKClassByPackageName.kt similarity index 100% rename from src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/resolveSerializerByPackageName.kt rename to src/jvmMain/kotlin/com/insanusmokrassar/sdi/utils/resolveKClassByPackageName.kt From a5bcddae6e9c0be229e79fc74c57e1c2c1a72193 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 16:32:30 +0600 Subject: [PATCH 06/11] add loadModule --- CHANGELOG.md | 1 + .../kotlin/com/insanusmokrassar/sdi/HelperTools.kt | 7 +++++++ .../kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt | 11 +++++++++++ 3 files changed, 19 insertions(+) create mode 100644 src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt create mode 100644 src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a4ef01..f9b7aad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.1.2 * All reflection support methods are internal +* Added `lodModule` functions for more useful working with modules loading ## 0.1.1 diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt new file mode 100644 index 0000000..dc40876 --- /dev/null +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt @@ -0,0 +1,7 @@ +package com.insanusmokrassar.sdi + +import kotlinx.serialization.ImplicitReflectionSerializer +import kotlinx.serialization.json.Json + +@ImplicitReflectionSerializer +fun loadModule(json: String): Module = Json.nonstrict.parse(Module.serializer(), json) diff --git a/src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt b/src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt new file mode 100644 index 0000000..b5c4804 --- /dev/null +++ b/src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt @@ -0,0 +1,11 @@ +package com.insanusmokrassar.sdi + +import kotlinx.io.InputStream +import kotlinx.serialization.ImplicitReflectionSerializer +import java.io.File + +@ImplicitReflectionSerializer +fun loadModule(stream: InputStream) = loadModule(stream.reader().readText()) + +@ImplicitReflectionSerializer +fun loadModule(file: File) = loadModule(file.inputStream()) From cee263adb6b7ca10fb553c20ba591a69a4e23406 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 16:34:26 +0600 Subject: [PATCH 07/11] in tests was included loadModule function --- src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt | 2 +- .../kotlin/com/insanusmokrassar/sdi/SimpleCustomObjectTest.kt | 2 +- src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleTest.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt b/src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt index 62abb6f..b3351cb 100644 --- a/src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt +++ b/src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt @@ -45,7 +45,7 @@ class ListTest { ] } """.trimIndent() - val module = Json.plain.parse(Module.serializer(), input) + val module = loadModule(input) (module[controllerName] as List_ParentalAPI) val controller = (module[controllerName] as List_Parent) controller.services.forEachIndexed { i, service -> diff --git a/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleCustomObjectTest.kt b/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleCustomObjectTest.kt index 23091e6..a6d358b 100644 --- a/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleCustomObjectTest.kt +++ b/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleCustomObjectTest.kt @@ -79,7 +79,7 @@ class SimpleCustomObjectTest { ] } """.trimIndent() - val module = Json.plain.parse(Module.serializer(), input) + val module = loadModule(input) (module[controllerName] as SimpleCustomObject_ControllerAPI) val controller = (module["controller"] as SimpleCustomObject_Controller) diff --git a/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleTest.kt b/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleTest.kt index a02fe3a..44d1b8d 100644 --- a/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleTest.kt +++ b/src/commonTest/kotlin/com/insanusmokrassar/sdi/SimpleTest.kt @@ -43,7 +43,7 @@ class SimpleTest { ] } """.trimIndent() - val module = Json.plain.parse(Module.serializer(), input) + val module = loadModule(input) (module[controllerName] as Simple_ControllerAPI) val controller = (module["controller"] as Simple_Controller) assertEquals(names.toList(), controller.service.names) From 2748c3f861de47114cb3cabaa245249120b8fd84 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 16:41:04 +0600 Subject: [PATCH 08/11] now Module is not serializable and instead of Serializer was created ModuleDeserializationStrategy --- CHANGELOG.md | 3 ++- .../kotlin/com/insanusmokrassar/sdi/HelperTools.kt | 2 +- .../com/insanusmokrassar/sdi/ModuleSerializer.kt | 11 +++-------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9b7aad..3ad891f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ ## 0.1.2 * All reflection support methods are internal -* Added `lodModule` functions for more useful working with modules loading +* Added `loadModule` functions for more useful working with modules loading +* `Module` now is not serializable and can be created only via `loadModule` functions ## 0.1.1 diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt index dc40876..f746b5c 100644 --- a/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt @@ -4,4 +4,4 @@ import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.json.Json @ImplicitReflectionSerializer -fun loadModule(json: String): Module = Json.nonstrict.parse(Module.serializer(), json) +fun loadModule(json: String): Module = Json.nonstrict.parse(ModuleDeserializerStrategy, json) diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt index 267f021..5f3ad09 100644 --- a/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt @@ -6,13 +6,10 @@ import kotlinx.serialization.internal.HashMapSerializer import kotlinx.serialization.internal.StringSerializer import kotlinx.serialization.json.* -@ImplicitReflectionSerializer -@Serializable(ModuleSerializer::class) -class Module(base: Map) : Map by base +class Module internal constructor(base: Map) : Map by base @ImplicitReflectionSerializer -@Serializer(Module::class) -internal object ModuleSerializer : KSerializer { +internal object ModuleDeserializerStrategy : DeserializationStrategy { private val internalSerializer = HashMapSerializer(StringSerializer, ContextSerializer(Any::class)) override val descriptor: SerialDescriptor get() = internalSerializer.descriptor @@ -27,7 +24,5 @@ internal object ModuleSerializer : KSerializer { return Module(map) } - override fun serialize(encoder: Encoder, obj: Module) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } + override fun patch(decoder: Decoder, old: Module): Module = throw UpdateNotSupportedException("Module") } From b3966beb328e709d31964237e0ab68d9542bac43 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 20:55:20 +0600 Subject: [PATCH 09/11] now it is possible to use custon Json to load Module --- .../kotlin/com/insanusmokrassar/sdi/HelperTools.kt | 5 ++++- .../kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt index f746b5c..4686f7a 100644 --- a/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt @@ -4,4 +4,7 @@ import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.json.Json @ImplicitReflectionSerializer -fun loadModule(json: String): Module = Json.nonstrict.parse(ModuleDeserializerStrategy, json) +fun Json.loadModule(json: String): Module = parse(ModuleDeserializerStrategy, json) + +@ImplicitReflectionSerializer +fun loadModule(json: String): Module = Json.nonstrict.loadModule(json) diff --git a/src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt b/src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt index b5c4804..e32d946 100644 --- a/src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt +++ b/src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt @@ -2,10 +2,17 @@ package com.insanusmokrassar.sdi import kotlinx.io.InputStream import kotlinx.serialization.ImplicitReflectionSerializer +import kotlinx.serialization.json.Json import java.io.File @ImplicitReflectionSerializer -fun loadModule(stream: InputStream) = loadModule(stream.reader().readText()) +fun Json.loadModule(stream: InputStream) = loadModule(stream.reader().readText()) @ImplicitReflectionSerializer -fun loadModule(file: File) = loadModule(file.inputStream()) +fun loadModule(stream: InputStream) = Json.nonstrict.loadModule(stream.reader().readText()) + +@ImplicitReflectionSerializer +fun Json.loadModule(file: File) = loadModule(file.inputStream()) + +@ImplicitReflectionSerializer +fun loadModule(file: File) = Json.nonstrict.loadModule(file.inputStream()) From fc0bd288e3e58ed1670ce5fc1ed6caaaecdb47f2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 20:56:03 +0600 Subject: [PATCH 10/11] refactor renames --- src/commonMain/kotlin/com/insanusmokrassar/sdi/Module.kt | 5 +++++ .../{ModuleSerializer.kt => ModuleDeserializerStrategy.kt} | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 src/commonMain/kotlin/com/insanusmokrassar/sdi/Module.kt rename src/commonMain/kotlin/com/insanusmokrassar/sdi/{ModuleSerializer.kt => ModuleDeserializerStrategy.kt} (90%) diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/Module.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/Module.kt new file mode 100644 index 0000000..ea376e6 --- /dev/null +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/Module.kt @@ -0,0 +1,5 @@ +package com.insanusmokrassar.sdi + +import kotlinx.serialization.ContextualSerialization + +class Module internal constructor(base: Map) : Map by base \ No newline at end of file diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleDeserializerStrategy.kt similarity index 90% rename from src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt rename to src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleDeserializerStrategy.kt index 5f3ad09..3313c4e 100644 --- a/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleDeserializerStrategy.kt @@ -6,8 +6,6 @@ import kotlinx.serialization.internal.HashMapSerializer import kotlinx.serialization.internal.StringSerializer import kotlinx.serialization.json.* -class Module internal constructor(base: Map) : Map by base - @ImplicitReflectionSerializer internal object ModuleDeserializerStrategy : DeserializationStrategy { private val internalSerializer = HashMapSerializer(StringSerializer, ContextSerializer(Any::class)) From 01edfc0d61a69e105381d722adba257e0ea641d9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 15 Feb 2020 12:15:42 +0600 Subject: [PATCH 11/11] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ad891f..efd50b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * All reflection support methods are internal * Added `loadModule` functions for more useful working with modules loading -* `Module` now is not serializable and can be created only via `loadModule` functions +* `Module` now is not serializable and can be created only via `loadModule` functions (at least, for some time) ## 0.1.1