From 3d21d3cab43ef31e61085eddc687024e42e92606 Mon Sep 17 00:00:00 2001 From: jershell Date: Sun, 15 Sep 2019 13:32:28 +0300 Subject: [PATCH 01/10] Update README.md Add the Bson format --- formats/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/formats/README.md b/formats/README.md index 69e06b56c0..9296c63a21 100644 --- a/formats/README.md +++ b/formats/README.md @@ -25,3 +25,11 @@ You can learn about "Human-Optimized Config Object Notation" or HOCON from libra * Platform: JVM only Allows serialization and deserialization of objects to and from [YAML](http://yaml.org). + +### Bson + +* GitHub repo: [jershell/kbson](https://github.com/jershell/kbson) +* Artifact ID: `com.github.jershell:kbson` +* Platform: JVM only + +Allows serialization and deserialization of objects to and from [BSON](https://docs.mongodb.com/manual/reference/bson-types/). From 4da9ef2592593ab7ec783c5bc944ad3f834689ce Mon Sep 17 00:00:00 2001 From: Paul de Vrieze Date: Tue, 17 Sep 2019 13:35:04 +0100 Subject: [PATCH 02/10] Add XML library to list of available formats. --- formats/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/formats/README.md b/formats/README.md index 9296c63a21..1621bd91d6 100644 --- a/formats/README.md +++ b/formats/README.md @@ -33,3 +33,14 @@ Allows serialization and deserialization of objects to and from [YAML](http://ya * Platform: JVM only Allows serialization and deserialization of objects to and from [BSON](https://docs.mongodb.com/manual/reference/bson-types/). + +### XML +* GitHub repo: [pdvrieze/xmlutil](https://github.com/pdvrieze/xmlutil) +* Artifact ID: `net.devrieze:xmlutil-serialization` +* Platform: JVM, Android, JavaScript + +This library allows for reading and writing of XML documents with the serialization library. +It is multiplatform, but as the xmlutil library (which handles the multiplatform xml bit) +delegates to platform specific parsers each platform needs to be implemented for each platform +specifically. The library is designed to handle existing formats that use features that would +not be available in other formats such as JSON. From 4fb08f8d30111ae1748820dbd163c29b322e2418 Mon Sep 17 00:00:00 2001 From: Eduard Wolf Date: Mon, 16 Sep 2019 15:58:00 +0200 Subject: [PATCH 03/10] Support optional values for typesafe config format Fixes: #211 --- .../serialization/config/ConfigReader.kt | 13 +++++++++++++ .../config/ConfigParserObjectsTest.kt | 7 ++++--- .../config/ConfigParserValuesTest.kt | 19 ++++++++++++++++++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/formats/config/src/main/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigReader.kt b/formats/config/src/main/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigReader.kt index 1dc3632b79..0c031fb75c 100644 --- a/formats/config/src/main/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigReader.kt +++ b/formats/config/src/main/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigReader.kt @@ -74,6 +74,18 @@ class ConfigParser(context: SerialModule = EmptyModule): AbstractSerialFormat(co } private inner class ConfigReader(val conf: Config) : ConfigConverter() { + private var ind = -1 + + override fun decodeElementIndex(desc: SerialDescriptor): Int { + while (++ind < desc.elementsCount) { + val name = desc.getTag(ind) + if (conf.hasPathOrNull(name)) { + return ind + } + } + return READ_DONE + } + private fun composeName(parentName: String, childName: String) = if (parentName.isEmpty()) childName else parentName + "." + childName @@ -92,6 +104,7 @@ class ConfigParser(context: SerialModule = EmptyModule): AbstractSerialFormat(co override fun beginStructure(desc: SerialDescriptor, vararg typeParams: KSerializer<*>): CompositeDecoder = when { desc.kind.listLike -> ListConfigReader(conf.getList(currentTag)) + desc.kind.objLike -> if (ind > -1) ConfigReader(conf.getConfig(currentTag)) else this desc.kind == StructureKind.MAP -> MapConfigReader(conf.getObject(currentTag)) else -> this } diff --git a/formats/config/src/test/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigParserObjectsTest.kt b/formats/config/src/test/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigParserObjectsTest.kt index ef2cb6a6b1..01fae769ed 100644 --- a/formats/config/src/test/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigParserObjectsTest.kt +++ b/formats/config/src/test/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigParserObjectsTest.kt @@ -31,7 +31,7 @@ class ConfigParserObjectsTest { data class Simple(val a: Int) @Serializable - data class ConfigObjectInner(val e: String) + data class ConfigObjectInner(val e: String, val f: Float = 1.1f) @Serializable data class ConfigObject(val a: Int, val b: ConfigObjectInner) @@ -68,7 +68,7 @@ class ConfigParserObjectsTest { inner = [{ a: 100500 }] ll = [[a, b],[x,z]] m : { - kek: {e: foo } + kek: {e: foo, f: 5.6 } bar: {e: baz } } """ @@ -92,7 +92,7 @@ class ConfigParserObjectsTest { assertEquals(listOf(1, 2, 3), iList) assertEquals(listOf(Simple(100500)), inner) assertEquals(listOf(listOf("a", "b"), listOf("x", "z")), ll) - assertEquals(mapOf("kek" to ConfigObjectInner("foo"), "bar" to ConfigObjectInner("baz")), m) + assertEquals(mapOf("kek" to ConfigObjectInner("foo", f = 5.6f), "bar" to ConfigObjectInner("baz")), m) } } @@ -133,6 +133,7 @@ class ConfigParserObjectsTest { val obj = ConfigParser.parse(conf, ConfigObject.serializer()) assertEquals(42, obj.a) assertEquals("foo", obj.b.e) + assertEquals(1.1f, obj.b.f) } @Test diff --git a/formats/config/src/test/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigParserValuesTest.kt b/formats/config/src/test/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigParserValuesTest.kt index c0c4ac60ef..9dda5ded6e 100644 --- a/formats/config/src/test/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigParserValuesTest.kt +++ b/formats/config/src/test/kotlin/org/jetbrains/kotlinx/serialization/config/ConfigParserValuesTest.kt @@ -31,7 +31,10 @@ class ConfigParserValuesTest() { data class StringConfig(val c: Char, val s: String) @Serializable - data class OtherConfig(val b: Boolean, val e: Choice, val u: Unit) + data class OtherConfig(val b: Boolean, val e: Choice, val u: Unit = Unit) + + @Serializable + data class WithDefault(val i: Int = 5, val s: String = "foo") @Serializable data class WithNullable(val i: Int?, val s: String?) @@ -67,6 +70,20 @@ class ConfigParserValuesTest() { assertEquals(true, obj.b) } + @Test + fun `deserialize default values`() { + val obj = deserializeConfig("", WithDefault.serializer()) + assertEquals(5, obj.i) + assertEquals("foo", obj.s) + } + + @Test + fun `overwrite default values`() { + val obj = deserializeConfig("i = 42, s = bar", WithDefault.serializer()) + assertEquals(42, obj.i) + assertEquals("bar", obj.s) + } + @Test fun `deserialize nullable types`() { val obj = deserializeConfig("i = 10, s = null", WithNullable.serializer()) From 1b20b53021eb45c105478d1c08c0908c10eb84aa Mon Sep 17 00:00:00 2001 From: DownloadPizza Date: Thu, 3 Oct 2019 22:34:04 +0200 Subject: [PATCH 04/10] Update README.MD No need for a String Array anymore in any of the new kotlin versions (since 1.3) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d70f7f2cf3..e9f6cb1fce 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ import kotlinx.serialization.json.* @Serializable data class Data(val a: Int, val b: String = "42") -fun main(args: Array) { +fun main() { // Json also has .Default configuration which provides more reasonable settings, // but is subject to change in future versions val json = Json(JsonConfiguration.Stable) From 75d3bf8d3000c84b4fa262da83b4bba741a0504a Mon Sep 17 00:00:00 2001 From: Stephen Samuel Date: Sun, 6 Oct 2019 22:35:58 -0500 Subject: [PATCH 05/10] Added Avro4k and sorted formats alphabetically --- formats/README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/formats/README.md b/formats/README.md index 1621bd91d6..d782714a20 100644 --- a/formats/README.md +++ b/formats/README.md @@ -18,13 +18,13 @@ You can learn about "Human-Optimized Config Object Notation" or HOCON from libra ## Other community-supported formats -### YAML +### Avro -* GitHub repo: [charleskorn/kaml](https://github.com/charleskorn/kaml) -* Artifact ID: `com.charleskorn.kaml:kaml` +* GitHub repo: [sksamuel/avro4k](https://github.com/sksamuel/avro4k) +* Artifact ID: `com.sksamuel.avro4k:avro4k` * Platform: JVM only -Allows serialization and deserialization of objects to and from [YAML](http://yaml.org). +This library allows serialization and deserialization of objects to and from [Avro](https://avro.apache.org). It will read and write from Avro binary or json streams or generate Avro Generic Records directly. It will also generate Avro schemas from data classes. The library allows for easy extension and overrides for custom schema formats, compatiblity with schemas defined outside out of the JVM and for types not supported out of the box. ### Bson @@ -44,3 +44,11 @@ It is multiplatform, but as the xmlutil library (which handles the multiplatform delegates to platform specific parsers each platform needs to be implemented for each platform specifically. The library is designed to handle existing formats that use features that would not be available in other formats such as JSON. + +### YAML + +* GitHub repo: [charleskorn/kaml](https://github.com/charleskorn/kaml) +* Artifact ID: `com.charleskorn.kaml:kaml` +* Platform: JVM only + +Allows serialization and deserialization of objects to and from [YAML](http://yaml.org). From 47395e315779ef86b892b64a359c387c16a761ee Mon Sep 17 00:00:00 2001 From: Ioannis Diamantidis Date: Sun, 13 Oct 2019 21:28:24 +0200 Subject: [PATCH 06/10] Fix broken links on the README.md file --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e9f6cb1fce..7674d42c0e 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,10 @@ You can open example projects for [JS](examples/example-js), [JVM](examples/exam * [Current status](#current-project-status) * [Library installing](#setup) + [Gradle](#gradle) - + [Gradle (with `plugins` block)](#gradle--with--plugins--block-) - + [Android/JVM](#android-jvm) - + [Multiplatform (common, JS, Native)](#multiplatform--common--js--native-) - + [Maven/JVM](#maven-jvm) + + [Gradle (with `plugins` block)](#gradle-with-plugins-block) + + [Android/JVM](#androidjvm) + + [Multiplatform (common, JS, Native)](#multiplatform-common-js-native) + + [Maven/JVM](#mavenjvm) + [Incompatible changes from older versions](#incompatible-changes) * [Troubleshooting IntelliJ IDEA](#troubleshooting-intellij-idea) * [Usage](docs/runtime_usage.md) From 341e7d86fd2fc2bb7320c76075631596658587ab Mon Sep 17 00:00:00 2001 From: Leonid Startsev Date: Mon, 14 Oct 2019 14:03:28 +0300 Subject: [PATCH 07/10] Format section 'incompatible changes' properly --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7674d42c0e..894bcbefa1 100644 --- a/README.md +++ b/README.md @@ -287,10 +287,14 @@ Add dependency on serialization runtime library: ### Incompatible changes -All versions of library before `0.13.0` are using Gradle metadata v0.4 and therefore it is recommended to use Gradle 4.8-5.1 to build +All versions of library before `0.13.0` are using Gradle metadata v0.4 and therefore it is recommended to use Gradle 4.8-5.1 to build. + Library versions `0.11.0` and higher require Kotlin 1.3.30 and higher and incompatible with previous versions. + All versions of library before `0.10.0` are using Gradle metadata v0.3 and therefore require Gradle 4.7 for build. + Maven plugin coordinates before Kotlin 1.3.20 were `kotlinx-maven-serialization-plugin`. + For deprecated `kotlin-platform-native` plugin, you need to use `kotlinx-serialization-native` plugin (see [#2210](https://github.com/JetBrains/kotlin-native/issues/2210#issuecomment-429753168)). ## Troubleshooting IntelliJ IDEA From 320a69dceb8366e4699d49f276a17030de30546f Mon Sep 17 00:00:00 2001 From: Stephen Samuel Date: Wed, 23 Oct 2019 14:50:37 -0500 Subject: [PATCH 08/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 894bcbefa1..a1ccb1ee0a 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ You may also want to keep all custom serializers you've defined. Platform artifacts have the same names as JVM one, but with additional suffix (e.g. `org.jetbrains.kotlinx:kotlinx-serialization-runtime-native`). For Native artifact, Gradle metadata is required (put the line `enableFeaturePreview('GRADLE_METADATA')` in your `gradle.properties`) and minimal supported version of Gradle is 5.3. -Typically, you need the following dependencies in your multiplatform project (don't forget to rename [source sets](https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#configuring-source-sets) according yo your setup): +Typically, you need the following dependencies in your multiplatform project (don't forget to rename [source sets](https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#configuring-source-sets) according to your setup): ```gradle sourceSets { From f4c9440bd7529a143fbe079969c041bda750466d Mon Sep 17 00:00:00 2001 From: Leonid Startsev Date: Thu, 31 Oct 2019 14:17:21 +0300 Subject: [PATCH 09/10] Create CONTRIBUTING.md --- CONTRIBUTING.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..d4016ea1ad --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Contributing + +## Report a bug + +Just use a 'bug report' template when creating a new issue. + +## Submit a PR + +The process of submitting a pull request depends on what kind of changes you have in it: + +#### Fix typo/documentation clarification + +You can open your PR directly against a `master` branch. + +#### Fix a minor bug + +Open your PR against the `dev` branch of the repository with a meaningful message in the description. + +#### Fix a bug in the library core/implement a new feature + +First, open an issue from 'feature request' template or describe in the existing issue what idea you are trying to implement +– probably it needs some tuning to be more aligned with the whole library design and vision. +After a design discussion, you can open a PR against the `dev` branch. + +## Propose/implement a new serialization format + +If you have created a new serialization format, you can keep it +in your repository to be able to perform proper maintenance and to have a separate release cycle. +You can submit a PR to the [list of community-supported formats](formats/README.md#other-community-supported-formats) with a description of your library. + +## Building this library + +You can find all the instructions [here](docs/building.md) From 8a8335d70c92256b07408a0fad8a60ca513ffd43 Mon Sep 17 00:00:00 2001 From: Leonid Startsev Date: Thu, 31 Oct 2019 14:20:51 +0300 Subject: [PATCH 10/10] Update building.md --- docs/building.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/building.md b/docs/building.md index 560ec670ca..ab4ea907fb 100644 --- a/docs/building.md +++ b/docs/building.md @@ -2,9 +2,10 @@ ## Runtime library -Kotlin Serialization runtime library itself is a [multiplatform](http://kotlinlang.org/docs/reference/multiplatform.html) project, -but it is still using an old multiplatform system from Kotlin 1.2. -To build library from the source and run all tests, use `./gradlew build`. To install it into the local Maven repository, run `./gradlew publishToMavenLocal`. +Kotlin Serialization runtime library itself is a [multiplatform](http://kotlinlang.org/docs/reference/multiplatform.html) project. +To build library from the source and run all tests, use `./gradlew build`. Corresponding platform tasks like `jvmTest`, `jsTest` and so on are also available. + +To install it into the local Maven repository, run `./gradlew publishToMavenLocal`. After that, you can include this library in arbitrary projects like usual gradle dependency: ```gradle @@ -19,8 +20,8 @@ dependencies { ``` To open project in Intellij IDEA, first run `./gradlew generateTestProto` from console. -Make sure you've set an option 'Use Gradle wrapper' on import to use a correct (4.7) version of Gradle. Note that Gradle 4.7 is not compatible with Java 10 or 11. -You may also need to mark `runtime/build/generated/source/proto/test/java` as 'Generated source root' to build project without delegating a build to Gradle. +Make sure you've set an option 'Use Gradle wrapper' on import to use a correct version of Gradle. +You may also need to mark `runtime/build/generated/source/proto/test/java` as 'Generated source root' to build project/run tests in IDE without delegating a build to Gradle. This requires Kotlin 1.3.11 and higher. To use snapshot version of compiler (if you have built it from sources), use flag `-Pbootstrap`. To compile and publish all Native artifacts, not only the host one, use `-Pnative.deploy=true`.