From afa5ebf2cbdadcf0aa424909f63b575222ab7b62 Mon Sep 17 00:00:00 2001 From: BenWoodworth Date: Fri, 24 Sep 2021 11:22:49 -0400 Subject: [PATCH] Update kotlinx.serialization to 1.3.0, and Kotlin to 1.5.31 --- README.md | 6 +++--- build.gradle.kts | 11 ++++++----- gradle.properties | 2 +- src/commonMain/kotlin/Nbt.kt | 7 ------- src/commonMain/kotlin/NbtDecoder.kt | 1 - src/commonMain/kotlin/NbtFormat.kt | 2 -- src/commonMain/kotlin/NbtTagSerializers.kt | 6 ++---- src/commonMain/kotlin/StringifiedNbt.kt | 10 ++-------- src/commonMain/kotlin/internal/DefaultNbtEncoder.kt | 3 +-- src/commonMain/kotlin/internal/NbtDecoder.kt | 8 ++++++-- .../kotlin/internal/DefaultNbtEncoderTest.kt | 2 +- src/commonTest/kotlin/internal/NbtDecoderTest.kt | 1 - .../kotlin/internal/RootClassSerializerTest.kt | 3 +-- 13 files changed, 23 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 1c0c662f..d4a8d8e3 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ [![Maven Central](https://img.shields.io/maven-central/v/net.benwoodworth.knbt/knbt)](https://search.maven.org/artifact/net.benwoodworth.knbt/knbt) [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/net.benwoodworth.knbt/knbt?server=https%3A%2F%2Fs01.oss.sonatype.org)](https://s01.oss.sonatype.org/content/repositories/snapshots/net/benwoodworth/knbt/knbt/) [![KDoc](https://img.shields.io/badge/api-KDoc-blue)](https://benwoodworth.github.io/knbt) -[![Kotlin](https://img.shields.io/badge/kotlin-1.5.0-blue.svg?logo=kotlin)](http://kotlinlang.org) -[![kotlinx.serialization](https://img.shields.io/badge/kotlinx.serialization-1.2.0-blue.svg?logo=kotlin)](https://github.com/Kotlin/kotlinx.serialization) +[![Kotlin](https://img.shields.io/badge/kotlin-1.5.31-blue.svg?logo=kotlin)](http://kotlinlang.org) +[![kotlinx.serialization](https://img.shields.io/badge/kotlinx.serialization-1.3.0-blue.svg?logo=kotlin)](https://github.com/Kotlin/kotlinx.serialization) An implementation of [Minecraft's NBT format](https://minecraft.fandom.com/wiki/NBT_format) for [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization). @@ -206,7 +206,7 @@ Replacement refactorings will be provided where possible for broken APIs. Change ```kotlin plugins { - kotlin("jvm") version "1.5.0" // or kotlin("multiplatform"), etc. + kotlin("jvm") version "1.5.31" // or kotlin("multiplatform"), etc. //kotlin("plugin.serialization") version "1.5.0" } diff --git a/build.gradle.kts b/build.gradle.kts index 39d6c74d..c510e71d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,8 +12,8 @@ System.getenv("GIT_REF")?.let { gitRef -> val isSnapshot = version.toString().contains("SNAPSHOT", true) plugins { - kotlin("multiplatform") version "1.5.0" - kotlin("plugin.serialization") version "1.5.0" + kotlin("multiplatform") version "1.5.31" + kotlin("plugin.serialization") version "1.5.31" id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.7.1" id("org.jetbrains.dokka") version "1.5.0" id("maven-publish") @@ -51,12 +51,13 @@ kotlin { watchosX86() mingwX64() + @Suppress("UNUSED_VARIABLE") sourceSets { configureEach { languageSettings.apply { - useExperimentalAnnotation("kotlin.RequiresOptIn") - useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") - useExperimentalAnnotation("net.benwoodworth.knbt.InternalNbtApi") + optIn("kotlin.RequiresOptIn") + optIn("kotlin.contracts.ExperimentalContracts") + optIn("net.benwoodworth.knbt.InternalNbtApi") } } diff --git a/gradle.properties b/gradle.properties index 6b90a922..b3e87790 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ group=net.benwoodworth.knbt version=0.10.0-SNAPSHOT -kotlinx_serialization_version=1.2.0 +kotlinx_serialization_version=1.3.0 okio_version=2.10.0 kotlin.code.style=official diff --git a/src/commonMain/kotlin/Nbt.kt b/src/commonMain/kotlin/Nbt.kt index c9be890f..86ea1d5a 100644 --- a/src/commonMain/kotlin/Nbt.kt +++ b/src/commonMain/kotlin/Nbt.kt @@ -10,12 +10,8 @@ import okio.Sink import okio.Source import okio.use -@OptIn(ExperimentalSerializationApi::class) public sealed class Nbt constructor( - @Suppress("EXPERIMENTAL_OVERRIDE") - @ExperimentalNbtApi override val configuration: NbtConfiguration, - override val serializersModule: SerializersModule, ) : NbtFormat, BinaryFormat { /** @@ -77,7 +73,6 @@ public fun Nbt(from: Nbt = DefaultNbt, builderAction: NbtBuilder.() -> Unit): Nb * Builder of the [Nbt] instance provided by `Nbt { ... }` factory function. */ @NbtDslMarker -@OptIn(ExperimentalNbtApi::class) public class NbtBuilder internal constructor(nbt: Nbt) { /** * The variant of NBT binary format to use. Required. @@ -124,7 +119,6 @@ public class NbtBuilder internal constructor(nbt: Nbt) { */ public var serializersModule: SerializersModule = nbt.serializersModule - @OptIn(ExperimentalSerializationApi::class, ExperimentalNbtApi::class) internal fun build(): Nbt { val variant = variant val compression = compression @@ -150,7 +144,6 @@ public class NbtBuilder internal constructor(nbt: Nbt) { } } -@OptIn(ExperimentalSerializationApi::class) private class NbtImpl( configuration: NbtConfiguration, serializersModule: SerializersModule, diff --git a/src/commonMain/kotlin/NbtDecoder.kt b/src/commonMain/kotlin/NbtDecoder.kt index b7cb8a18..e3c2959e 100644 --- a/src/commonMain/kotlin/NbtDecoder.kt +++ b/src/commonMain/kotlin/NbtDecoder.kt @@ -58,7 +58,6 @@ internal abstract class AbstractNbtDecoder : AbstractDecoder(), NbtDecoder, Comp final override fun decodeNbtTagElement(descriptor: SerialDescriptor, index: Int): NbtTag = decodeNbtTag() - @ExperimentalSerializationApi override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder = if (descriptor.kind == StructureKind.LIST) { beginList(descriptor) diff --git a/src/commonMain/kotlin/NbtFormat.kt b/src/commonMain/kotlin/NbtFormat.kt index 548180f3..3efda4ef 100644 --- a/src/commonMain/kotlin/NbtFormat.kt +++ b/src/commonMain/kotlin/NbtFormat.kt @@ -4,9 +4,7 @@ import kotlinx.serialization.* import kotlinx.serialization.descriptors.StructureKind import net.benwoodworth.knbt.internal.* -@OptIn(ExperimentalSerializationApi::class) public sealed interface NbtFormat : SerialFormat { - @ExperimentalNbtApi public val configuration: NbtFormatConfiguration /** diff --git a/src/commonMain/kotlin/NbtTagSerializers.kt b/src/commonMain/kotlin/NbtTagSerializers.kt index 1b247d4f..1f8f9a50 100644 --- a/src/commonMain/kotlin/NbtTagSerializers.kt +++ b/src/commonMain/kotlin/NbtTagSerializers.kt @@ -118,7 +118,6 @@ internal class NbtListSerializer( private class NbtListDescriptor( val elementDescriptor: SerialDescriptor, ) : SerialDescriptor by listSerialDescriptor(elementDescriptor) { - @ExperimentalSerializationApi override val serialName: String = "net.benwoodworth.knbt.NbtList" } } @@ -139,14 +138,13 @@ internal object NbtCompoundSerializer : KSerializer { private class NbtCompoundDescriptor( val elementDescriptor: SerialDescriptor, ) : SerialDescriptor by mapSerialDescriptor(String.serializer().descriptor, elementDescriptor) { - @ExperimentalSerializationApi override val serialName: String = "net.benwoodworth.knbt.NbtCompound" } } internal object NbtIntArraySerializer : KSerializer { + @OptIn(ExperimentalSerializationApi::class) private object NbtIntArrayDescriptor : SerialDescriptor by serialDescriptor() { - @ExperimentalSerializationApi override val serialName: String = "net.benwoodworth.knbt.NbtIntArray" } @@ -160,8 +158,8 @@ internal object NbtIntArraySerializer : KSerializer { } internal object NbtLongArraySerializer : KSerializer { + @OptIn(ExperimentalSerializationApi::class) private object NbtLongArrayDescriptor : SerialDescriptor by serialDescriptor() { - @ExperimentalSerializationApi override val serialName: String = "net.benwoodworth.knbt.NbtLongArray" } diff --git a/src/commonMain/kotlin/StringifiedNbt.kt b/src/commonMain/kotlin/StringifiedNbt.kt index b869154f..f675aa87 100644 --- a/src/commonMain/kotlin/StringifiedNbt.kt +++ b/src/commonMain/kotlin/StringifiedNbt.kt @@ -6,18 +6,14 @@ import kotlinx.serialization.modules.SerializersModule import net.benwoodworth.knbt.internal.StringifiedNbtWriter import kotlin.native.concurrent.ThreadLocal -@OptIn(ExperimentalSerializationApi::class) public sealed class StringifiedNbt constructor( - @Suppress("EXPERIMENTAL_OVERRIDE") - @ExperimentalNbtApi override val configuration: StringifiedNbtConfiguration, - override val serializersModule: SerializersModule, ) : NbtFormat, StringFormat { /** * The default instance of [StringifiedNbt] with default configuration. */ - @OptIn(ExperimentalNbtApi::class) + @OptIn(ExperimentalNbtApi::class, ExperimentalSerializationApi::class) @ThreadLocal public companion object Default : StringifiedNbt( configuration = StringifiedNbtConfiguration( @@ -65,7 +61,6 @@ public fun StringifiedNbt( * Builder of the [StringifiedNbt] instance provided by `StringifiedNbt { ... }` factory function. */ @NbtDslMarker -@OptIn(ExperimentalNbtApi::class) public class StringifiedNbtBuilder internal constructor(stringifiedNbt: StringifiedNbt) { /** * Specifies whether default values of Kotlin properties should be encoded. @@ -100,7 +95,7 @@ public class StringifiedNbtBuilder internal constructor(stringifiedNbt: Stringif */ public var serializersModule: SerializersModule = stringifiedNbt.serializersModule - @OptIn(ExperimentalSerializationApi::class, ExperimentalNbtApi::class) + @OptIn(ExperimentalNbtApi::class) internal fun build(): StringifiedNbt { if (!prettyPrint) { require(prettyPrintIndent == StringifiedNbt.configuration.prettyPrintIndent) { @@ -126,7 +121,6 @@ public class StringifiedNbtBuilder internal constructor(stringifiedNbt: Stringif } } -@OptIn(ExperimentalSerializationApi::class) private class StringifiedNbtImpl( configuration: StringifiedNbtConfiguration, serializersModule: SerializersModule, diff --git a/src/commonMain/kotlin/internal/DefaultNbtEncoder.kt b/src/commonMain/kotlin/internal/DefaultNbtEncoder.kt index b844dd33..3691a4dc 100644 --- a/src/commonMain/kotlin/internal/DefaultNbtEncoder.kt +++ b/src/commonMain/kotlin/internal/DefaultNbtEncoder.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.modules.SerializersModule import net.benwoodworth.knbt.* import net.benwoodworth.knbt.internal.NbtTagType.* -@ExperimentalSerializationApi +@OptIn(ExperimentalSerializationApi::class) internal class DefaultNbtEncoder( private val nbt: NbtFormat, private val writer: NbtWriter, @@ -124,7 +124,6 @@ internal class DefaultNbtEncoder( } } - @ExperimentalSerializationApi @OptIn(ExperimentalNbtApi::class) override fun shouldEncodeElementDefault(descriptor: SerialDescriptor, index: Int): Boolean = nbt.configuration.encodeDefaults diff --git a/src/commonMain/kotlin/internal/NbtDecoder.kt b/src/commonMain/kotlin/internal/NbtDecoder.kt index 1248a701..9fe9804c 100644 --- a/src/commonMain/kotlin/internal/NbtDecoder.kt +++ b/src/commonMain/kotlin/internal/NbtDecoder.kt @@ -41,7 +41,7 @@ private abstract class BaseNbtDecoder : AbstractNbtDecoder() { private fun expectTagType(expected: NbtTagType) { val actual = entryType if (expected != actual) { - throw NbtDecodingException("Expected ${expected}, but was ${actual}", getPath()) + throw NbtDecodingException("Expected $expected, but was $actual", getPath()) } } @@ -179,7 +179,6 @@ private abstract class BaseNbtDecoder : AbstractNbtDecoder() { final override fun decodeSerializableValue(deserializer: DeserializationStrategy, previousValue: T?): T = super.decodeSerializableValue(deserializer, previousValue) - @ExperimentalSerializationApi final override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder = super.beginStructure(descriptor) //endregion @@ -213,6 +212,7 @@ private abstract class CompoundNbtDecoder : BaseNbtDecoder() { override fun getPathNode(): NbtPath.Node = NbtPath.NameNode(compoundEntryInfo.name, entryType) + @OptIn(ExperimentalSerializationApi::class) override fun endStructure(descriptor: SerialDescriptor): Unit = reader.endCompound() } @@ -353,6 +353,7 @@ private class ListNbtDecoder( override fun beginEntry(): Boolean = reader.beginListEntry() + @OptIn(ExperimentalSerializationApi::class) override fun endStructure(descriptor: SerialDescriptor): Unit = reader.endList() } @@ -371,6 +372,7 @@ private class ByteArrayNbtDecoder( override fun beginEntry(): Boolean = reader.beginByteArrayEntry() + @OptIn(ExperimentalSerializationApi::class) override fun endStructure(descriptor: SerialDescriptor): Unit = reader.endByteArray() } @@ -389,6 +391,7 @@ private class IntArrayNbtDecoder( override fun beginEntry(): Boolean = reader.beginIntArrayEntry() + @OptIn(ExperimentalSerializationApi::class) override fun endStructure(descriptor: SerialDescriptor): Unit = reader.endIntArray() } @@ -407,5 +410,6 @@ private class LongArrayNbtDecoder( override fun beginEntry(): Boolean = reader.beginLongArrayEntry() + @OptIn(ExperimentalSerializationApi::class) override fun endStructure(descriptor: SerialDescriptor): Unit = reader.endLongArray() } diff --git a/src/commonTest/kotlin/internal/DefaultNbtEncoderTest.kt b/src/commonTest/kotlin/internal/DefaultNbtEncoderTest.kt index 89e14b84..24b62ca6 100644 --- a/src/commonTest/kotlin/internal/DefaultNbtEncoderTest.kt +++ b/src/commonTest/kotlin/internal/DefaultNbtEncoderTest.kt @@ -9,13 +9,13 @@ import kotlin.test.Test import kotlin.test.assertEquals class DefaultNbtEncoderTest { + @OptIn(ExperimentalSerializationApi::class) private fun assertEncodesCorrectly(tag: NbtTag, expectedLog: String) { val stringBuilder = StringBuilder() var actualTag: NbtTag? = null val writer = LoggingNbtWriter(TreeNbtWriter { actualTag = it }, stringBuilder) try { - @OptIn(ExperimentalSerializationApi::class) DefaultNbtEncoder(NbtFormat(), writer).encodeSerializableValue(NbtTag.serializer(), tag) } catch (e: Exception) { throw Exception("Error encoding. NbtWriter log: <\n$stringBuilder>", e) diff --git a/src/commonTest/kotlin/internal/NbtDecoderTest.kt b/src/commonTest/kotlin/internal/NbtDecoderTest.kt index 5b2c7b51..aa63c343 100644 --- a/src/commonTest/kotlin/internal/NbtDecoderTest.kt +++ b/src/commonTest/kotlin/internal/NbtDecoderTest.kt @@ -20,7 +20,6 @@ class NbtDecoderTest { val reader = LoggingNbtReader(TreeNbtReader(tag), stringBuilder) val actualValue = try { - @OptIn(ExperimentalSerializationApi::class) NbtDecoder(NbtFormat(), reader).decodeSerializableValue(serializer) } catch (e: Exception) { val log = stringBuilder.toString().trimIndent() diff --git a/src/commonTest/kotlin/internal/RootClassSerializerTest.kt b/src/commonTest/kotlin/internal/RootClassSerializerTest.kt index 9df564ad..c45ab6dd 100644 --- a/src/commonTest/kotlin/internal/RootClassSerializerTest.kt +++ b/src/commonTest/kotlin/internal/RootClassSerializerTest.kt @@ -1,6 +1,5 @@ package net.benwoodworth.knbt.internal -import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import net.benwoodworth.knbt.ExperimentalNbtApi @@ -10,7 +9,7 @@ import net.benwoodworth.knbt.put import kotlin.test.Test import kotlin.test.assertEquals -@OptIn(ExperimentalSerializationApi::class, ExperimentalNbtApi::class) +@OptIn(ExperimentalNbtApi::class) class RootClassSerializerTest { @Serializable @SerialName("root-name")