diff --git a/CHANGELOG.md b/CHANGELOG.md index efa70834..c0d617c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ - Public PluginManager mutability ### Fixed -- Proper json array index treatment +- Proper json array index treatment. +- Proper json index for single-value array. ### Security ## [0.4.0] diff --git a/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/Context.kt b/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/Context.kt index 3c2cf28b..b7e393cf 100644 --- a/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/Context.kt +++ b/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/Context.kt @@ -26,7 +26,7 @@ import kotlin.jvm.Synchronized public open class Context internal constructor( final override val name: Name, public val parent: Context?, - plugins: Set, + plugins: Set, // set of unattached plugins meta: Meta, ) : Named, MetaRepr, Provider, CoroutineScope { diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/JsonMeta.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/JsonMeta.kt index 0929a188..ea855ca4 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/JsonMeta.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/JsonMeta.kt @@ -56,7 +56,7 @@ private fun Meta.toJsonWithIndex(descriptor: NodeDescriptor?, indexValue: String } 1 -> { val (index, item) = items.entries.first() - val element = item.toJsonElement(itemDescriptor, null) + val element = item.toJsonElement(itemDescriptor, index) if (index == null) { elementMap[jsonKey] = element } else { diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MetaBuilder.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MetaBuilder.kt index 2f32e187..4574ce4b 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MetaBuilder.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MetaBuilder.kt @@ -2,6 +2,7 @@ package space.kscience.dataforge.meta import space.kscience.dataforge.misc.DFBuilder import space.kscience.dataforge.names.Name +import space.kscience.dataforge.names.NameToken import space.kscience.dataforge.names.asName import space.kscience.dataforge.values.EnumValue import space.kscience.dataforge.values.Value @@ -13,6 +14,8 @@ import kotlin.jvm.JvmName */ @DFBuilder public class MetaBuilder : AbstractMutableMeta() { + override val children: MutableMap> = LinkedHashMap() + override fun wrapNode(meta: Meta): MetaBuilder = if (meta is MetaBuilder) meta else meta.toMutableMeta() override fun empty(): MetaBuilder = MetaBuilder() diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt index b54c6534..6a8b0203 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt @@ -13,10 +13,10 @@ public interface MutableMeta> : TypedMeta, MutableItem * Changes in Meta are not thread safe. */ public abstract class AbstractMutableMeta> : AbstractTypedMeta(), MutableMeta { - protected val children: MutableMap> = LinkedHashMap() - override val items: Map> - get() = children + protected abstract val children: MutableMap> + + override val items: Map> get() = children //protected abstract fun itemChanged(name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/TypedMeta.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/TypedMeta.kt index cd1c3c47..f6f02c70 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/TypedMeta.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/TypedMeta.kt @@ -39,10 +39,15 @@ public abstract class MetaBase : Meta { override fun hashCode(): Int = items.hashCode() - override fun toString(): String = Json { - prettyPrint = true - useArrayPolymorphism = true - }.encodeToString(MetaSerializer, this) + override fun toString(): String = json.encodeToString(MetaSerializer, this) + + public companion object{ + private val json = Json { + prettyPrint = true + useArrayPolymorphism = true + } + + } } /**