Proper json index for single-value array

This commit is contained in:
Alexander Nozik 2021-07-15 12:10:56 +03:00
parent d2ea1a975e
commit a9cec666a3
6 changed files with 19 additions and 10 deletions

View File

@ -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]

View File

@ -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<Plugin>,
plugins: Set<Plugin>, // set of unattached plugins
meta: Meta,
) : Named, MetaRepr, Provider, CoroutineScope {

View File

@ -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 {

View File

@ -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<MetaBuilder>() {
override val children: MutableMap<NameToken, TypedMetaItem<MetaBuilder>> = LinkedHashMap()
override fun wrapNode(meta: Meta): MetaBuilder = if (meta is MetaBuilder) meta else meta.toMutableMeta()
override fun empty(): MetaBuilder = MetaBuilder()

View File

@ -13,10 +13,10 @@ public interface MutableMeta<out M : MutableMeta<M>> : TypedMeta<M>, MutableItem
* Changes in Meta are not thread safe.
*/
public abstract class AbstractMutableMeta<M : MutableMeta<M>> : AbstractTypedMeta<M>(), MutableMeta<M> {
protected val children: MutableMap<NameToken, TypedMetaItem<M>> = LinkedHashMap()
override val items: Map<NameToken, TypedMetaItem<M>>
get() = children
protected abstract val children: MutableMap<NameToken, TypedMetaItem<M>>
override val items: Map<NameToken, TypedMetaItem<M>> get() = children
//protected abstract fun itemChanged(name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?)

View File

@ -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
}
}
}
/**