improve serialization by using serializer<T>()

This commit is contained in:
ansgarz 2024-10-08 17:16:37 +02:00
parent 7f8d4c8b97
commit b5a7b12794
2 changed files with 5 additions and 8 deletions

View file

@ -169,9 +169,9 @@ tasks.register('installbinaires') {
dependsOn(uberjarServer, uberjarDesktop, uberjarSyspec) dependsOn(uberjarServer, uberjarDesktop, uberjarSyspec)
doLast { doLast {
println "Building binaries ..." println "Building binaries ..."
exec { commandLine("sh", "-c", "cd build/libs/ && native-image -jar provs-desktop.jar") } exec { commandLine("sh", "-c", "cd build/libs/ && native-image --no-fallback --initialize-at-build-time=kotlin.DeprecationLevel -jar provs-desktop.jar") }
exec { commandLine("sh", "-c", "cd build/libs/ && native-image -jar provs-server.jar") } exec { commandLine("sh", "-c", "cd build/libs/ && native-image --no-fallback --initialize-at-build-time=kotlin.DeprecationLevel -jar provs-server.jar") }
exec { commandLine("sh", "-c", "cd build/libs/ && native-image -jar provs-syspec.jar") } exec { commandLine("sh", "-c", "cd build/libs/ && native-image --no-fallback --initialize-at-build-time=kotlin.DeprecationLevel -jar provs-syspec.jar") }
exec { commandLine("sh", "-c", "sudo cp $projectRoot/build/libs/provs-desktop /usr/local/bin/") } exec { commandLine("sh", "-c", "sudo cp $projectRoot/build/libs/provs-desktop /usr/local/bin/") }
exec { commandLine("sh", "-c", "sudo cp $projectRoot/build/libs/provs-server /usr/local/bin/") } exec { commandLine("sh", "-c", "sudo cp $projectRoot/build/libs/provs-server /usr/local/bin/") }
exec { commandLine("sh", "-c", "sudo cp $projectRoot/build/libs/provs-syspec /usr/local/bin/") } exec { commandLine("sh", "-c", "sudo cp $projectRoot/build/libs/provs-syspec /usr/local/bin/") }

View file

@ -2,7 +2,6 @@ package org.domaindrivenarchitecture.provs.framework.core
import com.charleskorn.kaml.Yaml import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration import com.charleskorn.kaml.YamlConfiguration
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.serializer import kotlinx.serialization.serializer
import java.io.BufferedReader import java.io.BufferedReader
import java.io.File import java.io.File
@ -18,15 +17,13 @@ fun writeToFile(fileName: String, text: String) {
} }
@OptIn(InternalSerializationApi::class)
inline fun <reified T : Any> String.yamlToType() = Yaml(configuration = YamlConfiguration(strictMode = false)).decodeFromString( inline fun <reified T : Any> String.yamlToType() = Yaml(configuration = YamlConfiguration(strictMode = false)).decodeFromString(
T::class.serializer(), serializer<T>(),
this this
) )
@OptIn(InternalSerializationApi::class)
inline fun <reified T : Any> T.toYaml() = Yaml(configuration = YamlConfiguration(strictMode = false, encodeDefaults = false)).encodeToString( inline fun <reified T : Any> T.toYaml() = Yaml(configuration = YamlConfiguration(strictMode = false, encodeDefaults = false)).encodeToString(
T::class.serializer(), serializer<T>(),
this this
) )