From d75028c073ed174375a1ebcbfaa4eec63efd50e7 Mon Sep 17 00:00:00 2001 From: xn32 Date: Thu, 10 Nov 2022 16:51:42 +0100 Subject: [PATCH 1/4] Add third-party library for the JSON5 format (#2084) --- formats/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/formats/README.md b/formats/README.md index 85ab0366d9..e885049900 100644 --- a/formats/README.md +++ b/formats/README.md @@ -159,3 +159,11 @@ There are still some limitations (ordered properties). Allows serialization and deserialization of [Fixed Length Format files](https://www.ibm.com/docs/en/psfa/7.2.1?topic=format-fixed-length-files). Each property must be annotated with `@FixedLength` and there are still some limitations due to missing delimiters. + +### JSON5 + +* GitHub repo: [xn32/json5k](https://github.com/xn32/json5k) +* Artifact ID: `io.github.xn32:json5k` +* Platform: JVM only + +Library for the serialization to and deserialization from [JSON5](https://json5.org) text. From cf32cdc1759c19767999f4e538146ec64078cc43 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Mon, 14 Nov 2022 08:35:56 -0800 Subject: [PATCH 2/4] Improve README to provide a link to a Bazel example. (#2086) This resolves one aspect of #2066. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 6841e13d3f..9a71d82827 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Kotlin serialization consists of a compiler plugin, that generates visitor code * [Android](#android) * [Multiplatform (Common, JS, Native)](#multiplatform-common-js-native) * [Maven](#maven) + * [Bazel](#bazel) @@ -335,3 +336,9 @@ Add dependency on serialization runtime library: ${serialization.version} ``` + +### Bazel + +To setup the Kotlin compiler plugin for Bazel, follow [the +example](https://github.com/bazelbuild/rules_kotlin/tree/master/examples/plugin/src/serialization) +from the `rules_kotlin` repository. From dc950f5098162a3f8dd742d04b95f9a0405470e1 Mon Sep 17 00:00:00 2001 From: Igor Kozlenko Date: Wed, 16 Nov 2022 19:20:16 +0100 Subject: [PATCH 3/4] Fix typo (#2098) Remove double `is` --- docs/json.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/json.md b/docs/json.md index 59e52d3e20..b6f18a04ce 100644 --- a/docs/json.md +++ b/docs/json.md @@ -548,7 +548,7 @@ Note that the execution will fail if the structure of the data is otherwise diff ### Json element builders You can construct instances of specific [JsonElement] subtypes using the respective builder functions -[buildJsonArray] and [buildJsonObject]. They provide a DSL to define the resulting JSON structure. It is +[buildJsonArray] and [buildJsonObject]. They provide a DSL to define the resulting JSON structure. It is similar to Kotlin standard library collection builders, but with a JSON-specific convenience of more type-specific overloads and inner builder functions. The following example shows all the key features: From 33104957873448189eb242413646b58883623e0a Mon Sep 17 00:00:00 2001 From: Vasily Vasilkov Date: Thu, 29 Dec 2022 21:13:39 +0400 Subject: [PATCH 4/4] Add stable hashCode()/equals() calculation to PrimitiveSerialDescriptor (#2136) Fixes #2135 --- .../serialization/internal/Primitives.kt | 7 +++++ .../PrimitiveSerialDescriptorTest.kt | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 core/commonTest/src/kotlinx/serialization/PrimitiveSerialDescriptorTest.kt diff --git a/core/commonMain/src/kotlinx/serialization/internal/Primitives.kt b/core/commonMain/src/kotlinx/serialization/internal/Primitives.kt index 5de1fe2fe4..816109e52f 100644 --- a/core/commonMain/src/kotlinx/serialization/internal/Primitives.kt +++ b/core/commonMain/src/kotlinx/serialization/internal/Primitives.kt @@ -58,6 +58,13 @@ internal class PrimitiveSerialDescriptor( override fun getElementDescriptor(index: Int): SerialDescriptor = error() override fun getElementAnnotations(index: Int): List = error() override fun toString(): String = "PrimitiveDescriptor($serialName)" + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is PrimitiveSerialDescriptor) return false + if (serialName == other.serialName && kind == other.kind) return true + return false + } + override fun hashCode() = serialName.hashCode() + 31 * kind.hashCode() private fun error(): Nothing = throw IllegalStateException("Primitive descriptor does not have elements") } diff --git a/core/commonTest/src/kotlinx/serialization/PrimitiveSerialDescriptorTest.kt b/core/commonTest/src/kotlinx/serialization/PrimitiveSerialDescriptorTest.kt new file mode 100644 index 0000000000..deafc08549 --- /dev/null +++ b/core/commonTest/src/kotlinx/serialization/PrimitiveSerialDescriptorTest.kt @@ -0,0 +1,29 @@ +package kotlinx.serialization + +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.internal.PrimitiveSerialDescriptor +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotSame + +class PrimitiveSerialDescriptorTest { + + @Test + fun testEqualsImplemented() { + val first = PrimitiveSerialDescriptor("test_name", PrimitiveKind.LONG) + val second = PrimitiveSerialDescriptor("test_name", PrimitiveKind.LONG) + + assertNotSame(first, second) + assertEquals(first, second) + } + + @Test + fun testHashCodeStability() { + val first = PrimitiveSerialDescriptor("test_name", PrimitiveKind.LONG) + val second = PrimitiveSerialDescriptor("test_name", PrimitiveKind.LONG) + + assertNotSame(first, second) + assertEquals(first.hashCode(), second.hashCode()) + } + +}