Proper json index for single-value array
This commit is contained in:
parent
d2ea1a975e
commit
a9cec666a3
@ -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]
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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<*>?)
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user