Fix json serialization.

This commit is contained in:
Alexander Nozik 2023-07-26 16:47:12 +03:00
parent cfa20eedba
commit de476fb273
10 changed files with 15 additions and 97 deletions

View File

@ -5,6 +5,7 @@
### Added
### Changed
- Meta to Json serializer now serializes a single item with index as an array. It is important for plotly integration.
### Deprecated

View File

@ -1,49 +0,0 @@
[![JetBrains Research](https://jb.gg/badges/research.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
[![DOI](https://zenodo.org/badge/148831678.svg)](https://zenodo.org/badge/latestdoi/148831678)
![Gradle build](https://github.com/mipt-npm/dataforge-core/workflows/Gradle%20build/badge.svg)
<hr/>
* ### [dataforge-context](dataforge-context)
>
>
> **Maturity**: DEVELOPMENT
<hr/>
* ### [dataforge-data](dataforge-data)
>
>
> **Maturity**: EXPERIMENTAL
<hr/>
* ### [dataforge-io](dataforge-io)
>
>
> **Maturity**: PROTOTYPE
<hr/>
* ### [dataforge-meta](dataforge-meta)
>
>
> **Maturity**: DEVELOPMENT
<hr/>
* ### [dataforge-scripting](dataforge-scripting)
>
>
> **Maturity**: PROTOTYPE
<hr/>
* ### [dataforge-workspace](dataforge-workspace)
>
>
> **Maturity**: EXPERIMENTAL
<hr/>
* ### [dataforge-io-yaml](dataforge-io/dataforge-io-yaml)
> YAML meta converters and Front Matter envelope format
>
> **Maturity**: PROTOTYPE
<hr/>

View File

@ -9,7 +9,7 @@ plugins {
allprojects {
group = "space.kscience"
version = "0.6.2-dev-kotlin-1.9.0"
version = "0.6.2-dev-2"
}
subprojects {

View File

@ -10,8 +10,8 @@ kscience {
jvm()
js()
native()
useSerialization("1.4.1")
useSerialization("1.4.1", sourceSet = space.kscience.gradle.DependencySourceSet.TEST) {
useSerialization()
useSerialization(sourceSet = space.kscience.gradle.DependencySourceSet.TEST) {
cbor()
}
dependencies {

View File

@ -4,10 +4,6 @@ plugins {
description = "YAML meta IO"
repositories {
mavenCentral()
}
kscience {
jvm()
js()
@ -20,10 +16,6 @@ kscience {
}
}
repositories{
maven("https://dl.bintray.com/mamoe/yamlkt")
}
readme{
maturity = space.kscience.gradle.Maturity.PROTOTYPE
description ="""

View File

@ -6,7 +6,7 @@ kscience {
jvm()
js()
native()
useSerialization("1.4.1"){
useSerialization{
json()
}
}

View File

@ -23,7 +23,6 @@ public fun Value.toJson(descriptor: MetaDescriptor? = null): JsonElement = when
}
//Use these methods to customize JSON key mapping
@Suppress("NULLABLE_EXTENSION_OPERATOR_WITH_SAFE_CALL_RECEIVER")
private fun String.toJsonKey(descriptor: MetaDescriptor?) = descriptor?.attributes?.get("jsonName").string ?: toString()
private fun Meta.toJsonWithIndex(descriptor: MetaDescriptor?, index: String?): JsonElement = if (items.isEmpty()) {
@ -35,9 +34,13 @@ private fun Meta.toJsonWithIndex(descriptor: MetaDescriptor?, index: String?): J
val childDescriptor = descriptor?.children?.get(body)
if (list.size == 1) {
val (token, element) = list.first()
//do not add empty element
//do not add an empty element
val child: JsonElement = element.toJsonWithIndex(childDescriptor, token.index)
if(token.index == null) {
body to child
} else {
body to JsonArray(listOf(child))
}
} else {
val elements: List<JsonElement> = list.sortedBy { it.key.index }.mapIndexed { index, entry ->
//Use index if it is not equal to the item order

View File

@ -1,29 +0,0 @@
> #### Artifact:
>
> This module artifact: `${group}:${name}:${version}`.
>
>
> [![Maven Central](https://img.shields.io/maven-central/v/space.kscience/${name}.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22space.kscience%22%20AND%20a:%22${name}%22)
>
> **Gradle:**
>
> ```gradle
> repositories {
> maven { url 'https://repo.kotlin.link' }
> }
>
> dependencies {
> implementation '${group}:${name}:${version}'
> }
> ```
> **Gradle Kotlin DSL:**
>
> ```kotlin
> repositories {
> maven("https://https://repo.kotlin.link")
> }
>
> dependencies {
> implementation("${group}:${name}:${version}")
> }
> ```

View File

@ -3,4 +3,4 @@
![Gradle build](https://github.com/mipt-npm/dataforge-core/workflows/Gradle%20build/badge.svg)
$modules
${modules}

View File

@ -6,4 +6,4 @@ kotlin.mpp.stability.nowarn=true
kotlin.incremental.js.ir=true
kotlin.native.ignoreDisabledTargets=true
toolsVersion=0.14.9-kotlin-1.9.0
toolsVersion=0.14.9-kotlin-1.8.20