Proper json index for single-value array
This commit is contained in:
parent
d2ea1a975e
commit
a9cec666a3
@ -18,7 +18,8 @@
|
|||||||
- Public PluginManager mutability
|
- Public PluginManager mutability
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Proper json array index treatment
|
- Proper json array index treatment.
|
||||||
|
- Proper json index for single-value array.
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
## [0.4.0]
|
## [0.4.0]
|
||||||
|
@ -26,7 +26,7 @@ import kotlin.jvm.Synchronized
|
|||||||
public open class Context internal constructor(
|
public open class Context internal constructor(
|
||||||
final override val name: Name,
|
final override val name: Name,
|
||||||
public val parent: Context?,
|
public val parent: Context?,
|
||||||
plugins: Set<Plugin>,
|
plugins: Set<Plugin>, // set of unattached plugins
|
||||||
meta: Meta,
|
meta: Meta,
|
||||||
) : Named, MetaRepr, Provider, CoroutineScope {
|
) : Named, MetaRepr, Provider, CoroutineScope {
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ private fun Meta.toJsonWithIndex(descriptor: NodeDescriptor?, indexValue: String
|
|||||||
}
|
}
|
||||||
1 -> {
|
1 -> {
|
||||||
val (index, item) = items.entries.first()
|
val (index, item) = items.entries.first()
|
||||||
val element = item.toJsonElement(itemDescriptor, null)
|
val element = item.toJsonElement(itemDescriptor, index)
|
||||||
if (index == null) {
|
if (index == null) {
|
||||||
elementMap[jsonKey] = element
|
elementMap[jsonKey] = element
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,6 +2,7 @@ package space.kscience.dataforge.meta
|
|||||||
|
|
||||||
import space.kscience.dataforge.misc.DFBuilder
|
import space.kscience.dataforge.misc.DFBuilder
|
||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.Name
|
||||||
|
import space.kscience.dataforge.names.NameToken
|
||||||
import space.kscience.dataforge.names.asName
|
import space.kscience.dataforge.names.asName
|
||||||
import space.kscience.dataforge.values.EnumValue
|
import space.kscience.dataforge.values.EnumValue
|
||||||
import space.kscience.dataforge.values.Value
|
import space.kscience.dataforge.values.Value
|
||||||
@ -13,6 +14,8 @@ import kotlin.jvm.JvmName
|
|||||||
*/
|
*/
|
||||||
@DFBuilder
|
@DFBuilder
|
||||||
public class MetaBuilder : AbstractMutableMeta<MetaBuilder>() {
|
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 wrapNode(meta: Meta): MetaBuilder = if (meta is MetaBuilder) meta else meta.toMutableMeta()
|
||||||
override fun empty(): MetaBuilder = MetaBuilder()
|
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.
|
* Changes in Meta are not thread safe.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractMutableMeta<M : MutableMeta<M>> : AbstractTypedMeta<M>(), MutableMeta<M> {
|
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>>
|
protected abstract val children: MutableMap<NameToken, TypedMetaItem<M>>
|
||||||
get() = children
|
|
||||||
|
override val items: Map<NameToken, TypedMetaItem<M>> get() = children
|
||||||
|
|
||||||
//protected abstract fun itemChanged(name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?)
|
//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 hashCode(): Int = items.hashCode()
|
||||||
|
|
||||||
override fun toString(): String = Json {
|
override fun toString(): String = json.encodeToString(MetaSerializer, this)
|
||||||
prettyPrint = true
|
|
||||||
useArrayPolymorphism = true
|
public companion object{
|
||||||
}.encodeToString(MetaSerializer, this)
|
private val json = Json {
|
||||||
|
prettyPrint = true
|
||||||
|
useArrayPolymorphism = true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user