mirror of
https://github.com/InsanusMokrassar/SDI.git
synced 2024-12-28 03:27:23 +00:00
update dependencies and code after it
This commit is contained in:
parent
bd6abae994
commit
d4bca9d09f
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
## 0.4.0
|
## 0.4.0
|
||||||
|
|
||||||
|
**ALL PROJECT HAS MIGRATED FROM PACKAGE `com.insanusmokrassar` TO `dev.inmo`**
|
||||||
|
|
||||||
|
* `Kotlin`: `1.3.72` -> `1.4.10`
|
||||||
|
* `Serialization`: `0.20.0` -> `1.0.1`
|
||||||
|
|
||||||
|
|
||||||
## 0.3.1
|
## 0.3.1
|
||||||
|
|
||||||
* `Kotlin`: `1.3.71` -> `1.3.72`
|
* `Kotlin`: `1.3.71` -> `1.3.72`
|
||||||
|
@ -37,7 +37,7 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation kotlin('stdlib')
|
implementation kotlin('stdlib')
|
||||||
api kotlin('reflect')
|
api kotlin('reflect')
|
||||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
api "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlin_serialisation_runtime_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commonTest {
|
commonTest {
|
||||||
@ -46,11 +46,6 @@ kotlin {
|
|||||||
implementation kotlin('test-annotations-common')
|
implementation kotlin('test-annotations-common')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jvmMain {
|
|
||||||
dependencies {
|
|
||||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jvmTest {
|
jvmTest {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation kotlin('test-junit')
|
implementation kotlin('test-junit')
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
kotlin_version=1.3.72
|
kotlin_version=1.4.10
|
||||||
kotlin_serialisation_runtime_version=0.20.0
|
kotlin_serialisation_runtime_version=1.0.1
|
||||||
|
|
||||||
gradle_bintray_plugin_version=1.8.5
|
gradle_bintray_plugin_version=1.8.5
|
||||||
github_release_plugin_version=2.2.12
|
github_release_plugin_version=2.2.12
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package com.insanusmokrassar.sdi
|
|
||||||
|
|
||||||
import kotlinx.serialization.ContextualSerialization
|
|
||||||
|
|
||||||
class Module internal constructor(base: Map<String, @ContextualSerialization Any>) : Map<String, Any> by base
|
|
@ -1,6 +1,5 @@
|
|||||||
package com.insanusmokrassar.sdi
|
package dev.inmo.sdi
|
||||||
|
|
||||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.modules.SerializersModuleBuilder
|
import kotlinx.serialization.modules.SerializersModuleBuilder
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
@ -8,15 +7,13 @@ import kotlin.reflect.KClass
|
|||||||
internal val nonStrictJson = Json {
|
internal val nonStrictJson = Json {
|
||||||
isLenient = true
|
isLenient = true
|
||||||
ignoreUnknownKeys = true
|
ignoreUnknownKeys = true
|
||||||
serializeSpecialFloatingPointValues = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
fun Json.loadModule(
|
fun Json.loadModule(
|
||||||
json: String,
|
json: String,
|
||||||
vararg additionalClassesToInclude: KClass<*>,
|
vararg additionalClassesToInclude: KClass<*>,
|
||||||
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null
|
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null
|
||||||
): Module = parse(
|
): Module = decodeFromString(
|
||||||
if (moduleBuilder != null) {
|
if (moduleBuilder != null) {
|
||||||
ModuleDeserializerStrategy(moduleBuilder, *additionalClassesToInclude)
|
ModuleDeserializerStrategy(moduleBuilder, *additionalClassesToInclude)
|
||||||
} else {
|
} else {
|
||||||
@ -25,7 +22,6 @@ fun Json.loadModule(
|
|||||||
json
|
json
|
||||||
)
|
)
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
fun loadModule(
|
fun loadModule(
|
||||||
json: String,
|
json: String,
|
||||||
vararg additionalClassesToInclude: KClass<*>,
|
vararg additionalClassesToInclude: KClass<*>,
|
5
src/commonMain/kotlin/dev/inmo/sdi/Module.kt
Normal file
5
src/commonMain/kotlin/dev/inmo/sdi/Module.kt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.sdi
|
||||||
|
|
||||||
|
import kotlinx.serialization.Contextual
|
||||||
|
|
||||||
|
class Module internal constructor(base: Map<String, @Contextual Any>) : Map<String, Any> by base
|
@ -1,36 +1,36 @@
|
|||||||
package com.insanusmokrassar.sdi
|
package dev.inmo.sdi
|
||||||
|
|
||||||
import com.insanusmokrassar.sdi.utils.createModuleBasedOnConfigRoot
|
import dev.inmo.sdi.utils.createModuleBasedOnConfigRoot
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.builtins.MapSerializer
|
import kotlinx.serialization.builtins.MapSerializer
|
||||||
import kotlinx.serialization.builtins.serializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
import kotlinx.serialization.modules.SerializersModuleBuilder
|
import kotlinx.serialization.modules.SerializersModuleBuilder
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
internal class ModuleDeserializerStrategy(
|
internal class ModuleDeserializerStrategy(
|
||||||
private val moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null,
|
private val moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null,
|
||||||
private vararg val additionalClassesToInclude: KClass<*>
|
private vararg val additionalClassesToInclude: KClass<*>
|
||||||
) : DeserializationStrategy<Module> {
|
) : DeserializationStrategy<Module> {
|
||||||
private val internalSerializer = MapSerializer(String.serializer(), ContextSerializer(Any::class))
|
private val internalSerializer = MapSerializer(String.serializer(), ContextualSerializer(Any::class))
|
||||||
override val descriptor: SerialDescriptor
|
override val descriptor: SerialDescriptor
|
||||||
get() = internalSerializer.descriptor
|
get() = internalSerializer.descriptor
|
||||||
|
|
||||||
|
@InternalSerializationApi
|
||||||
override fun deserialize(decoder: Decoder): Module {
|
override fun deserialize(decoder: Decoder): Module {
|
||||||
val json = JsonObjectSerializer.deserialize(decoder)
|
val json = JsonObject.serializer().deserialize(decoder)
|
||||||
val jsonSerialFormat = createModuleBasedOnConfigRoot(
|
val jsonSerialFormat = createModuleBasedOnConfigRoot(
|
||||||
json,
|
json,
|
||||||
moduleBuilder,
|
moduleBuilder,
|
||||||
decoder.context,
|
decoder.serializersModule,
|
||||||
*additionalClassesToInclude
|
*additionalClassesToInclude
|
||||||
)
|
)
|
||||||
val resultJson = JsonObject(
|
val resultJson = JsonObject(
|
||||||
json.keys.associateWith { JsonPrimitive(it) }
|
json.keys.associateWith { JsonPrimitive(it) }
|
||||||
)
|
)
|
||||||
val map = jsonSerialFormat.fromJson(internalSerializer, resultJson)
|
val map = jsonSerialFormat.decodeFromJsonElement(internalSerializer, resultJson)
|
||||||
return Module(map)
|
return Module(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun patch(decoder: Decoder, old: Module): Module = throw UpdateNotSupportedException("Module")
|
|
||||||
}
|
}
|
@ -1,25 +1,25 @@
|
|||||||
package com.insanusmokrassar.sdi.utils
|
package dev.inmo.sdi.utils
|
||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
import kotlinx.serialization.modules.SerializersModuleBuilder
|
import kotlinx.serialization.modules.SerializersModuleBuilder
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
internal object AlreadyRegisteredException : Exception()
|
internal object AlreadyRegisteredException : Exception()
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
internal class DependencyResolver<T : Any>(
|
internal class DependencyResolver<T : Any>(
|
||||||
serialModuleBuilder: SerializersModuleBuilder,
|
serialModuleBuilder: SerializersModuleBuilder,
|
||||||
kClass: KClass<T>,
|
kClass: KClass<T>,
|
||||||
private val formatterGetter: () -> Json,
|
private val formatterGetter: () -> Json,
|
||||||
private val dependencyGetter: (String) -> Any
|
private val dependencyGetter: (String) -> Any
|
||||||
) : KSerializer<T> {
|
) : KSerializer<T> {
|
||||||
private val originalSerializer: KSerializer<T> = try {
|
@InternalSerializationApi
|
||||||
kClass.serializer()
|
private val originalSerializer: KSerializer<T> = kClass.serializerOrNull() ?: ContextualSerializer(kClass)
|
||||||
} catch (e: Exception) {
|
|
||||||
ContextSerializer(kClass)
|
|
||||||
}
|
|
||||||
private val objectsCache = mutableMapOf<String, T>()
|
private val objectsCache = mutableMapOf<String, T>()
|
||||||
|
@InternalSerializationApi
|
||||||
override val descriptor: SerialDescriptor = originalSerializer.descriptor
|
override val descriptor: SerialDescriptor = originalSerializer.descriptor
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -39,8 +39,9 @@ internal class DependencyResolver<T : Any>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@InternalSerializationApi
|
||||||
override fun deserialize(decoder: Decoder): T {
|
override fun deserialize(decoder: Decoder): T {
|
||||||
val decoded = decoder.decodeSerializableValue(JsonElementSerializer)
|
val decoded = decoder.decodeSerializableValue(JsonElement.serializer())
|
||||||
return when {
|
return when {
|
||||||
decoded is JsonPrimitive && decoded.contentOrNull != null -> decoded.content.let { dependencyName ->
|
decoded is JsonPrimitive && decoded.contentOrNull != null -> decoded.content.let { dependencyName ->
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@ -49,14 +50,15 @@ internal class DependencyResolver<T : Any>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
decoded is JsonArray -> {
|
decoded is JsonArray -> {
|
||||||
val serializer = resolveSerializerByPackageName(decoded.getPrimitive(0).content)
|
val serializer = resolveSerializerByPackageName(decoded[0].jsonPrimitive.content)
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
formatterGetter().fromJson(serializer, decoded[1]) as T
|
formatterGetter().decodeFromJsonElement(serializer, decoded[1]) as T
|
||||||
}
|
}
|
||||||
else -> formatterGetter().fromJson(originalSerializer, decoded)
|
else -> formatterGetter().decodeFromJsonElement(originalSerializer, decoded)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@InternalSerializationApi
|
||||||
override fun serialize(encoder: Encoder, value: T) {
|
override fun serialize(encoder: Encoder, value: T) {
|
||||||
objectsCache.keys.firstOrNull {
|
objectsCache.keys.firstOrNull {
|
||||||
objectsCache[it] === value
|
objectsCache[it] === value
|
@ -1,6 +1,5 @@
|
|||||||
package com.insanusmokrassar.sdi.utils
|
package dev.inmo.sdi.utils
|
||||||
|
|
||||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
|
||||||
import kotlinx.serialization.InternalSerializationApi
|
import kotlinx.serialization.InternalSerializationApi
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
import kotlinx.serialization.modules.*
|
import kotlinx.serialization.modules.*
|
||||||
@ -18,15 +17,15 @@ private fun JsonElement.resolvePackageName(currentKey: String, otherDependencies
|
|||||||
}
|
}
|
||||||
} ?: throw IllegalArgumentException("Value on dependency name \"$currentKey\" is invalid: provided $this, but expected package name or other dependency name string")
|
} ?: throw IllegalArgumentException("Value on dependency name \"$currentKey\" is invalid: provided $this, but expected package name or other dependency name string")
|
||||||
is JsonObject -> return currentKey to null
|
is JsonObject -> return currentKey to null
|
||||||
is JsonArray -> return getPrimitive(0).contentOrNull ?.let { it to null } ?: throw IllegalArgumentException("Value on first argument of dependency value must be its package as a string, but was provided ${get(0)}")
|
is JsonArray -> return get(0).jsonPrimitive.contentOrNull ?.let { it to null } ?: throw IllegalArgumentException("Value on first argument of dependency value must be its package as a string, but was provided ${get(0)}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
@InternalSerializationApi
|
||||||
internal fun createModuleBasedOnConfigRoot(
|
internal fun createModuleBasedOnConfigRoot(
|
||||||
jsonObject: JsonObject,
|
jsonObject: JsonObject,
|
||||||
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null,
|
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null,
|
||||||
baseContext: SerialModule,
|
baseContext: SerializersModule,
|
||||||
vararg additionalClassesToInclude: KClass<*>
|
vararg additionalClassesToInclude: KClass<*>
|
||||||
): Json {
|
): Json {
|
||||||
lateinit var caches: Map<String, () -> Any>
|
lateinit var caches: Map<String, () -> Any>
|
||||||
@ -53,7 +52,7 @@ internal fun createModuleBasedOnConfigRoot(
|
|||||||
}
|
}
|
||||||
is JsonArray -> {
|
is JsonArray -> {
|
||||||
if (elemValue.size > 1) {
|
if (elemValue.size > 1) {
|
||||||
elemValue.getObject(1)
|
elemValue[1].jsonObject
|
||||||
} else {
|
} else {
|
||||||
JsonObject(emptyMap())
|
JsonObject(emptyMap())
|
||||||
}
|
}
|
||||||
@ -61,7 +60,7 @@ internal fun createModuleBasedOnConfigRoot(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val serializer = resolveSerializerByPackageName(packageName)
|
val serializer = resolveSerializerByPackageName(packageName)
|
||||||
return@callback jsonStringFormat.fromJson(serializer, argumentsObject) as Any
|
return@callback jsonStringFormat.decodeFromJsonElement(serializer, argumentsObject) as Any
|
||||||
}
|
}
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
|
||||||
@ -105,10 +104,10 @@ internal fun createModuleBasedOnConfigRoot(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return Json(
|
return Json {
|
||||||
configuration = JsonConfiguration(useArrayPolymorphism = true),
|
useArrayPolymorphism = true
|
||||||
context = context
|
serializersModule = context
|
||||||
).also {
|
}.also {
|
||||||
jsonStringFormat = it
|
jsonStringFormat = it
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package com.insanusmokrassar.sdi.utils
|
package dev.inmo.sdi.utils
|
||||||
|
|
||||||
import kotlinx.serialization.InternalSerializationApi
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.KSerializer
|
|
||||||
import kotlinx.serialization.modules.*
|
import kotlinx.serialization.modules.*
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ fun <T : Any> SerializersModuleBuilder.optionalContextual(
|
|||||||
) = try {
|
) = try {
|
||||||
contextual(kClass, kSerializer)
|
contextual(kClass, kSerializer)
|
||||||
true
|
true
|
||||||
} catch (e: SerializerAlreadyRegisteredException) {
|
} catch (e: SerializationException) {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
@ -1,18 +1,21 @@
|
|||||||
package com.insanusmokrassar.sdi.utils
|
package dev.inmo.sdi.utils
|
||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.reflect.KType
|
||||||
|
|
||||||
internal expect fun resolveKClassByPackageName(packageName: String): KClass<*>
|
internal expect fun resolveKClassByPackageName(packageName: String): KClass<*>
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
@InternalSerializationApi
|
||||||
internal fun <T : Any> resolveSerializerByKClass(kClass: KClass<T>): KSerializer<T> = kClass.serializer()
|
internal fun <T : Any> resolveSerializerByKClass(kClass: KClass<T>): KSerializer<T> = kClass.serializer()
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
@InternalSerializationApi
|
||||||
internal fun resolveSerializerByPackageName(packageName: String): KSerializer<*> = resolveSerializerByKClass(
|
internal fun resolveSerializerByPackageName(packageName: String): KSerializer<*> = resolveSerializerByKClass(
|
||||||
resolveKClassByPackageName(packageName)
|
resolveKClassByPackageName(packageName)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internal expect val <T : Any> KClass<T>.supertypes: List<KType>
|
||||||
|
|
||||||
internal val KClass<*>.allSubclasses: Set<KClass<*>>
|
internal val KClass<*>.allSubclasses: Set<KClass<*>>
|
||||||
get() {
|
get() {
|
||||||
val subclasses = mutableSetOf<KClass<*>>()
|
val subclasses = mutableSetOf<KClass<*>>()
|
@ -1,4 +1,4 @@
|
|||||||
package com.insanusmokrassar.sdi
|
package dev.inmo.sdi
|
||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
@ -12,11 +12,10 @@ interface List_ChildAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class List_Parent(override val services: List<@ContextualSerialization List_ChildAPI>) : List_ParentalAPI
|
class List_Parent(override val services: List<@Contextual List_ChildAPI>) : List_ParentalAPI
|
||||||
@Serializable
|
@Serializable
|
||||||
class List_Child(override val names: List<String>) : List_ChildAPI
|
class List_Child(override val names: List<String>) : List_ChildAPI
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
class ListTest {
|
class ListTest {
|
||||||
val servicesNum = 10
|
val servicesNum = 10
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.insanusmokrassar.sdi
|
package dev.inmo.sdi
|
||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
@ -12,28 +12,32 @@ interface SimpleCustomObject_ServiceAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class SimpleCustomObject_Controller(@ContextualSerialization val service: SimpleCustomObject_ServiceAPI) : SimpleCustomObject_ControllerAPI {
|
class SimpleCustomObject_Controller(@Contextual val service: SimpleCustomObject_ServiceAPI) :
|
||||||
|
SimpleCustomObject_ControllerAPI {
|
||||||
override fun showUp() {
|
override fun showUp() {
|
||||||
println("Inited with name \"${service.names}\"")
|
println("Inited with name \"${service.names}\"")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class SimpleCustomObject_CustomController1(@ContextualSerialization val service: SimpleCustomObject_ServiceAPI) : SimpleCustomObject_ControllerAPI {
|
class SimpleCustomObject_CustomController1(@Contextual val service: SimpleCustomObject_ServiceAPI) :
|
||||||
|
SimpleCustomObject_ControllerAPI {
|
||||||
override fun showUp() {
|
override fun showUp() {
|
||||||
println("Inited with name \"${service.names}\"")
|
println("Inited with name \"${service.names}\"")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class SimpleCustomObject_CustomController2(@ContextualSerialization val service: SimpleCustomObject_BusinessService) : SimpleCustomObject_ControllerAPI {
|
class SimpleCustomObject_CustomController2(@Contextual val service: SimpleCustomObject_BusinessService) :
|
||||||
|
SimpleCustomObject_ControllerAPI {
|
||||||
override fun showUp() {
|
override fun showUp() {
|
||||||
println("Inited with name \"${service.names}\"")
|
println("Inited with name \"${service.names}\"")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class SimpleCustomObject_CustomController3(@ContextualSerialization val service: SimpleCustomObject_ServiceAPI) : SimpleCustomObject_ControllerAPI {
|
class SimpleCustomObject_CustomController3(@Contextual val service: SimpleCustomObject_ServiceAPI) :
|
||||||
|
SimpleCustomObject_ControllerAPI {
|
||||||
override fun showUp() {
|
override fun showUp() {
|
||||||
println("Inited with name \"${service.names}\"")
|
println("Inited with name \"${service.names}\"")
|
||||||
}
|
}
|
||||||
@ -43,7 +47,6 @@ class SimpleCustomObject_BusinessService(override val names: List<String>) : Sim
|
|||||||
@Serializable
|
@Serializable
|
||||||
class SimpleCustomObject_BusinessService1(override val names: List<String>) : SimpleCustomObject_ServiceAPI
|
class SimpleCustomObject_BusinessService1(override val names: List<String>) : SimpleCustomObject_ServiceAPI
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
class SimpleCustomObjectTest {
|
class SimpleCustomObjectTest {
|
||||||
@Test
|
@Test
|
||||||
fun test_that_simple_config_correctly_work() {
|
fun test_that_simple_config_correctly_work() {
|
@ -1,4 +1,4 @@
|
|||||||
package com.insanusmokrassar.sdi
|
package dev.inmo.sdi
|
||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
@ -12,7 +12,7 @@ interface Simple_ServiceAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class Simple_Controller(@ContextualSerialization val service: Simple_ServiceAPI) : Simple_ControllerAPI {
|
class Simple_Controller(@Contextual val service: Simple_ServiceAPI) : Simple_ControllerAPI {
|
||||||
override fun showUp() {
|
override fun showUp() {
|
||||||
println("Inited with name \"${service.names}\"")
|
println("Inited with name \"${service.names}\"")
|
||||||
}
|
}
|
||||||
@ -20,7 +20,6 @@ class Simple_Controller(@ContextualSerialization val service: Simple_ServiceAPI)
|
|||||||
@Serializable
|
@Serializable
|
||||||
class Simple_BusinessService(override val names: List<String>) : Simple_ServiceAPI
|
class Simple_BusinessService(override val names: List<String>) : Simple_ServiceAPI
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
class SimpleTest {
|
class SimpleTest {
|
||||||
@Test
|
@Test
|
||||||
fun test_that_simple_config_correctly_work() {
|
fun test_that_simple_config_correctly_work() {
|
@ -1,5 +0,0 @@
|
|||||||
package com.insanusmokrassar.sdi.utils
|
|
||||||
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
actual fun resolveKClassByPackageName(packageName: String): KClass<*> = Class.forName(packageName).kotlin
|
|
@ -1,34 +1,33 @@
|
|||||||
package com.insanusmokrassar.sdi
|
package dev.inmo.sdi
|
||||||
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.modules.SerializersModuleBuilder
|
import kotlinx.serialization.modules.SerializersModuleBuilder
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
fun Json.loadModule(
|
fun Json.loadModule(
|
||||||
stream: InputStream,
|
stream: InputStream,
|
||||||
vararg additionalClassesToInclude: KClass<*>,
|
vararg additionalClassesToInclude: KClass<*>,
|
||||||
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null
|
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null
|
||||||
) = loadModule(stream.reader().readText(), *additionalClassesToInclude, moduleBuilder = moduleBuilder)
|
) = loadModule(stream.reader().readText(), *additionalClassesToInclude, moduleBuilder = moduleBuilder)
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
fun loadModule(
|
fun loadModule(
|
||||||
stream: InputStream,
|
stream: InputStream,
|
||||||
vararg additionalClassesToInclude: KClass<*>,
|
vararg additionalClassesToInclude: KClass<*>,
|
||||||
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null
|
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null
|
||||||
) = nonStrictJson.loadModule(stream, *additionalClassesToInclude, moduleBuilder = moduleBuilder)
|
) = nonStrictJson.loadModule(stream, *additionalClassesToInclude, moduleBuilder = moduleBuilder)
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
fun Json.loadModule(
|
fun Json.loadModule(
|
||||||
file: File,
|
file: File,
|
||||||
vararg additionalClassesToInclude: KClass<*>,
|
vararg additionalClassesToInclude: KClass<*>,
|
||||||
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null
|
moduleBuilder: (SerializersModuleBuilder.() -> Unit)? = null
|
||||||
) = loadModule(file.inputStream(), *additionalClassesToInclude, moduleBuilder = moduleBuilder)
|
) = loadModule(file.inputStream(), *additionalClassesToInclude, moduleBuilder = moduleBuilder)
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
fun loadModule(
|
fun loadModule(
|
||||||
file: File,
|
file: File,
|
||||||
vararg additionalClassesToInclude: KClass<*>,
|
vararg additionalClassesToInclude: KClass<*>,
|
@ -0,0 +1,8 @@
|
|||||||
|
package dev.inmo.sdi.utils
|
||||||
|
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.reflect.KType
|
||||||
|
|
||||||
|
actual fun resolveKClassByPackageName(packageName: String): KClass<*> = Class.forName(packageName).kotlin
|
||||||
|
internal actual val <T : Any> KClass<T>.supertypes: List<KType>
|
||||||
|
get() = supertypes
|
Loading…
Reference in New Issue
Block a user