diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt index 2ef329e..50516de 100644 --- a/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/ModuleSerializer.kt @@ -13,7 +13,7 @@ class Module(base: Map) : Map @ImplicitReflectionSerializer @Serializer(Module::class) -object ModuleSerializer : KSerializer { +internal object ModuleSerializer : KSerializer { private val internalSerializer = HashMapSerializer(StringSerializer, ContextSerializer(Any::class)) override val descriptor: SerialDescriptor get() = internalSerializer.descriptor diff --git a/src/commonTest/kotlin/com/insanusmokrassar/sdi/DeserializationTest.kt b/src/commonTest/kotlin/com/insanusmokrassar/sdi/DeserializationTest.kt index f4378f0..4947c8a 100644 --- a/src/commonTest/kotlin/com/insanusmokrassar/sdi/DeserializationTest.kt +++ b/src/commonTest/kotlin/com/insanusmokrassar/sdi/DeserializationTest.kt @@ -2,8 +2,7 @@ package com.insanusmokrassar.sdi import kotlinx.serialization.* import kotlinx.serialization.json.Json -import kotlin.test.Test -import kotlin.test.assertTrue +import kotlin.test.* interface ControllerAPI { fun showUp() @@ -13,7 +12,7 @@ interface ServiceAPI { } @Serializable -class Controller(@ContextualSerialization private val service: ServiceAPI) : ControllerAPI { +class Controller(@ContextualSerialization val service: ServiceAPI) : ControllerAPI { override fun showUp() { println("Inited with name \"${service.names}\"") } @@ -25,12 +24,13 @@ class BusinessService(override val names: List) : ServiceAPI class DeserializationTest { @Test fun test_that_simple_config_correctly_work() { + val names = arrayOf("nameOne", "nameTwo") val input = """ { "service": [ "com.insanusmokrassar.sdi.BusinessService", { - "names": ["nameOne", "nameTwo"] + "names": ${names.joinToString(prefix = "[", postfix = "]") { "\"$it\"" }} } ], "controller": [ @@ -41,7 +41,9 @@ class DeserializationTest { ] } """.trimIndent() - val module = Json.plain.parse(ModuleSerializer, input) - (module["controller"] as ControllerAPI).showUp() + val module = Json.plain.parse(Module.serializer(), input) + (module["controller"] as ControllerAPI) + val controller = (module["controller"] as Controller) + assertEquals(names.toList(), controller.service.names) } }