jvmMain.StartPluginSerializer.jvm.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micro_utils.startup.plugin-jvm Show documentation
Show all versions of micro_utils.startup.plugin-jvm Show documentation
It is set of projects with micro tools for avoiding of routines coding
package dev.inmo.micro_utils.startup.plugin
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
internal actual fun alternativeDeserialize(decoder: Decoder): StartPlugin? {
val kclass = Class.forName(decoder.decodeString()).kotlin
return (kclass.objectInstance ?: kclass.constructors.first { it.parameters.isEmpty() }.call()) as StartPlugin
}
internal actual fun alternativeSerialize(
encoder: Encoder,
value: StartPlugin
): Boolean {
encoder.encodeString(value::class.java.canonicalName ?: return false)
return true
}