From 62a76f2c868e9d142753075e7a319eed50e13753 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 13 Nov 2020 10:42:03 +0300 Subject: [PATCH] Fix serialization problems in Group --- .../kotlin/hep/dataforge/vision/VisionGroupBase.kt | 8 +++++--- .../kotlin/hep/dataforge/vision/solid/SolidGroup.kt | 6 +++++- .../kotlin/hep/dataforge/vision/solid/serialization.kt | 2 +- .../kotlin/hep/dataforge/vision/solid/PropertyTest.kt | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt index af8fee4e..fa3567b6 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt @@ -13,10 +13,12 @@ import kotlinx.serialization.Transient @SerialName("vision.group") public open class VisionGroupBase : VisionBase(), MutableVisionGroup { - //protected abstract val _children: MutableMap - + /** + * Internal mutable container for group children + * TODO made protected due to https://github.com/Kotlin/kotlinx.serialization/issues/1200 + */ @SerialName("children") - protected val childrenInternal = LinkedHashMap() + protected open val childrenInternal: MutableMap = LinkedHashMap() /** * A map of top level named children diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt index d4c76661..d441ab6c 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt @@ -93,13 +93,17 @@ public fun MutableVisionGroup.group(name: String, action: SolidGroup.() -> Unit */ @Serializable(PrototypesSerializer::class) internal class Prototypes( - override var children: MutableMap = LinkedHashMap(), + children: Map = emptyMap(), ) : VisionGroupBase(), PrototypeHolder { override fun styleSheet(block: StyleSheet.() -> Unit) { error("Can't define stylesheet for prototypes block") } + init { + this.childrenInternal.putAll(children) + } + override var properties: Config? get() = null set(_) { diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/serialization.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/serialization.kt index c5b0a435..fafc0c5c 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/serialization.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/serialization.kt @@ -91,7 +91,7 @@ internal object PrototypesSerializer : KSerializer { override fun deserialize(decoder: Decoder): MutableVisionGroup { val map = mapSerializer.deserialize(decoder) - return Prototypes(map as? MutableMap ?: LinkedHashMap(map)) + return Prototypes(map) } override fun serialize(encoder: Encoder, value: MutableVisionGroup) { diff --git a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/PropertyTest.kt b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/PropertyTest.kt index a12679e5..02a0b661 100644 --- a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/PropertyTest.kt +++ b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/PropertyTest.kt @@ -60,7 +60,7 @@ class PropertyTest { @Test fun testProxyStyleProperty() { var box: Proxy? = null - val group = SolidGroup().apply { + val group = SolidGroup{ styleSheet { set("testStyle") { SolidMaterial.MATERIAL_COLOR_KEY put "#555555"