mirror of
https://github.com/InsanusMokrassar/SDI.git
synced 2025-11-15 10:50:03 +00:00
init
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user