From 62916d0c6710b4a89ef2beaef994a0af13280986 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 19 Aug 2019 22:42:08 +0300 Subject: [PATCH] Name and serialization fix --- build.gradle.kts | 2 +- .../commonMain/kotlin/hep/dataforge/io/MetaSerializer.kt | 6 +++++- .../src/commonMain/kotlin/hep/dataforge/names/Name.kt | 4 +--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 016a350e..0ebdc138 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("scientifik.publish") version "0.1.4" apply false } -val dataforgeVersion by extra("0.1.3") +val dataforgeVersion by extra("0.1.4-dev-1") val bintrayRepo by extra("dataforge") val githubProject by extra("dataforge-core") diff --git a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/MetaSerializer.kt b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/MetaSerializer.kt index e1a754eb..d72dc71d 100644 --- a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/MetaSerializer.kt +++ b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/MetaSerializer.kt @@ -4,6 +4,7 @@ import hep.dataforge.meta.Config import hep.dataforge.meta.Meta import hep.dataforge.meta.toConfig import hep.dataforge.names.Name +import hep.dataforge.names.NameToken import hep.dataforge.names.toName import kotlinx.serialization.* import kotlinx.serialization.internal.StringDescriptor @@ -11,7 +12,7 @@ import kotlinx.serialization.json.JsonObjectSerializer @Serializer(Name::class) object NameSerializer : KSerializer { - override val descriptor: SerialDescriptor = StringDescriptor + override val descriptor: SerialDescriptor = StringDescriptor.withName("Name") override fun deserialize(decoder: Decoder): Name { return decoder.decodeString().toName() @@ -22,6 +23,9 @@ object NameSerializer : KSerializer { } } +@Serializer(NameToken::class) +object NameTokenSerializer: KSerializer + /** * Serialized for meta */ diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt index 070a8f75..0531a818 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt @@ -139,9 +139,7 @@ fun String.toName(): Name { * Convert the [String] to a [Name] by simply wrapping it in a single name token without parsing. * The input string could contain dots and braces, but they are just escaped, not parsed. */ -fun String.asName(): Name { - return NameToken(this).asName() -} +fun String.asName(): Name = if(isBlank()) EmptyName else NameToken(this).asName() operator fun NameToken.plus(other: Name): Name = Name(listOf(this) + other.tokens)