SDI/src/commonTest/kotlin/com/insanusmokrassar/sdi/DeserializationTest.kt

48 lines
1.2 KiB
Kotlin

package com.insanusmokrassar.sdi
import kotlinx.serialization.*
import kotlinx.serialization.json.Json
import kotlin.test.Test
interface ControllerAPI {
fun showUp()
}
interface ServiceAPI {
val name: String
}
@Serializable
class Controller(@ContextualSerialization private val service : ServiceAPI) :
ControllerAPI {
override fun showUp() {
println("Inited with name \"${service.name}\"")
}
}
@Serializable
class BusinessService : ServiceAPI {
@Transient
override val name = "Example of business name"
}
@ImplicitReflectionSerializer
class DeserializationTest {
@Test
fun `Test_that_simple_config_correctly_work`() {
val input = """
{
"service": [
"com.insanusmokrassar.sdi.BusinessService"
],
"controller": [
"com.insanusmokrassar.sdi.Controller",
{
"service": "service"
}
]
}
""".trimIndent()
val module = Json.plain.parse(ModuleSerializer, input)
(module["controller"] as ControllerAPI).showUp()
}
}