Workarround serialization bug

This commit is contained in:
Alexander Nozik 2021-11-30 21:27:08 +03:00
parent 8d74bc55d1
commit e7f0e1e4fc
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
11 changed files with 32 additions and 24 deletions

View File

@ -4,7 +4,7 @@ plugins {
// kotlin("js") version "1.5.30" apply false
}
val dataforgeVersion by extra("0.5.2-dev-3")
val dataforgeVersion by extra("0.5.2")
val fxVersion by extra("11")
allprojects {
@ -16,7 +16,7 @@ allprojects {
}
group = "space.kscience"
version = "0.2.0-dev-25"
version = "0.2.0"
}
subprojects {

View File

@ -7,7 +7,7 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.html.div
import kotlinx.html.h1
import space.kscience.dataforge.context.Global
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.names.Name
import space.kscience.visionforge.solid.*
import space.kscience.visionforge.three.server.*
@ -15,7 +15,7 @@ import space.kscience.visionforge.visionManager
import kotlin.random.Random
fun main() {
val satContext = Global.buildContext ("sat") {
val satContext = Context("sat") {
plugin(Solids)
}

View File

@ -4,4 +4,7 @@ kotlin.mpp.stability.nowarn=true
kotlin.jupyter.add.scanner=false
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G
org.gradle.parallel=true
org.gradle.parallel=true
publishing.github=false
publishing.sonatype=false

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,5 +1,6 @@
package space.kscience.visionforge
import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@ -29,7 +30,7 @@ internal data class MetaListener(
@SerialName("vision")
public open class VisionBase(
@Transient override var parent: VisionGroup? = null,
protected var properties: MutableMeta? = null
@EncodeDefault protected var properties: MutableMeta? = null,
) : Vision {
@Synchronized
@ -131,7 +132,6 @@ public open class VisionBase(
override val descriptor: MetaDescriptor? get() = null
override fun invalidateProperty(propertyName: Name) {
if (propertyName == STYLE_KEY) {
styles.mapNotNull { getStyle(it) }.asSequence()

View File

@ -1,5 +1,6 @@
package space.kscience.visionforge
import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@ -16,7 +17,7 @@ private class StructureChangeListener(val owner: Any?, val callback: VisionGroup
@Serializable
@SerialName("vision.group")
public open class VisionGroupBase(
@SerialName("children") protected val childrenInternal: MutableMap<NameToken, Vision> = LinkedHashMap(),
@EncodeDefault @SerialName("children") protected val childrenInternal: MutableMap<NameToken, Vision> = LinkedHashMap(),
) : VisionBase(), MutableVisionGroup {
/**
@ -102,21 +103,19 @@ public open class VisionGroupBase(
/**
* Recursively create a child group
*/
private fun createGroups(name: Name): VisionGroupBase {
return when {
name.isEmpty() -> error("Should be unreachable")
name.length == 1 -> {
val token = name.tokens.first()
when (val current = children[token]) {
null -> createGroup().also { child ->
attachChild(token, child)
}
is VisionGroupBase -> current
else -> error("Can't create group with name $name because it exists and not a group")
private fun createGroups(name: Name): VisionGroupBase = when {
name.isEmpty() -> error("Should be unreachable")
name.length == 1 -> {
val token = name.tokens.first()
when (val current = children[token]) {
null -> createGroup().also { child ->
attachChild(token, child)
}
is VisionGroupBase -> current
else -> error("Can't create group with name $name because it exists and not a group")
}
else -> createGroups(name.tokens.first().asName()).createGroups(name.cutFirst())
}
else -> createGroups(name.tokens.first().asName()).createGroups(name.cutFirst())
}
/**

View File

@ -1,5 +1,6 @@
package space.kscience.visionforge
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.PolymorphicSerializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
@ -68,12 +69,14 @@ public class VisionManager(meta: Meta) : AbstractPlugin(meta) {
}
}
@OptIn(ExperimentalSerializationApi::class)
public val defaultJson: Json = Json {
serializersModule = defaultSerialModule
prettyPrint = true
useArrayPolymorphism = false
encodeDefaults = false
ignoreUnknownKeys = true
explicitNulls = false
}
internal val visionSerializer: PolymorphicSerializer<Vision> = PolymorphicSerializer(Vision::class)

View File

@ -37,8 +37,7 @@ fun FlowContent.renderVisionFragment(
@DFExperimental
class HtmlTagTest {
fun VisionOutput.base(block: VisionBase.() -> Unit) =
VisionBase().apply(block)
fun VisionOutput.base(block: VisionBase.() -> Unit) = VisionBase().apply(block)
val fragment: HtmlVisionFragment = {
div {

View File

@ -18,6 +18,7 @@ import space.kscience.visionforge.html.VisionTagConsumer.Companion.OUTPUT_FETCH_
import space.kscience.visionforge.html.VisionTagConsumer.Companion.OUTPUT_NAME_ATTRIBUTE
import kotlin.reflect.KClass
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.ExperimentalTime
public class VisionClient : AbstractPlugin() {
override val tag: PluginTag get() = Companion.tag
@ -56,6 +57,7 @@ public class VisionClient : AbstractPlugin() {
private fun Element.getFlag(attribute: String): Boolean = attributes[attribute]?.value != null
@OptIn(ExperimentalTime::class)
private fun renderVision(name: String, element: Element, vision: Vision?, outputMeta: Meta) {
if (vision != null) {
val renderer = findRendererFor(vision) ?: error("Could nof find renderer for $vision")

View File

@ -15,6 +15,7 @@ public class VisionOfPlotly private constructor() : VisionBase() {
public constructor(plot: Plot) : this() {
properties = plot.meta
}
public val plot: Plot get() = Plot(meta)
}

View File

@ -44,6 +44,7 @@ import java.net.URI
import kotlin.collections.set
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.ExperimentalTime
/**
@ -121,7 +122,7 @@ public class VisionServer internal constructor(
/**
* Server a map of visions without providing explicit html page for them
*/
@OptIn(DFExperimental::class)
@OptIn(DFExperimental::class, ExperimentalTime::class)
public fun serveVisions(route: Route, visions: Map<Name, Vision>): Unit = route {
application.log.info("Serving visions $visions at $route")