diff --git a/buildSrc/src/main/kotlin/source-sets-conventions.gradle.kts b/buildSrc/src/main/kotlin/source-sets-conventions.gradle.kts index 6aca5431a..c6b3a0b15 100644 --- a/buildSrc/src/main/kotlin/source-sets-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/source-sets-conventions.gradle.kts @@ -69,7 +69,6 @@ kotlin { progressiveMode = true optIn("kotlin.ExperimentalMultiplatform") - optIn("kotlin.ExperimentalStdlibApi") optIn("kotlinx.serialization.InternalSerializationApi") } } diff --git a/core/api/kotlinx-serialization-core.api b/core/api/kotlinx-serialization-core.api index c99f769cd..0ac51c851 100644 --- a/core/api/kotlinx-serialization-core.api +++ b/core/api/kotlinx-serialization-core.api @@ -199,6 +199,7 @@ public final class kotlinx/serialization/builtins/BuiltinSerializersKt { public static final fun serializer (Lkotlin/jvm/internal/ShortCompanionObject;)Lkotlinx/serialization/KSerializer; public static final fun serializer (Lkotlin/jvm/internal/StringCompanionObject;)Lkotlinx/serialization/KSerializer; public static final fun serializer (Lkotlin/time/Duration$Companion;)Lkotlinx/serialization/KSerializer; + public static final fun serializer (Lkotlin/uuid/Uuid$Companion;)Lkotlinx/serialization/KSerializer; } public final class kotlinx/serialization/builtins/LongAsStringSerializer : kotlinx/serialization/KSerializer { @@ -1293,6 +1294,15 @@ public final class kotlinx/serialization/internal/UnitSerializer : kotlinx/seria public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lkotlin/Unit;)V } +public final class kotlinx/serialization/internal/UuidSerializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Lkotlinx/serialization/internal/UuidSerializer; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lkotlin/uuid/Uuid; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lkotlin/uuid/Uuid;)V +} + public final class kotlinx/serialization/modules/PolymorphicModuleBuilder { public fun (Lkotlin/reflect/KClass;Lkotlinx/serialization/KSerializer;)V public synthetic fun (Lkotlin/reflect/KClass;Lkotlinx/serialization/KSerializer;ILkotlin/jvm/internal/DefaultConstructorMarker;)V diff --git a/core/api/kotlinx-serialization-core.klib.api b/core/api/kotlinx-serialization-core.klib.api index 0520a19ab..fbb167383 100644 --- a/core/api/kotlinx-serialization-core.klib.api +++ b/core/api/kotlinx-serialization-core.klib.api @@ -534,6 +534,7 @@ final class kotlinx.serialization/UnknownFieldException : kotlinx.serialization/ constructor (kotlin/Int) // kotlinx.serialization/UnknownFieldException.|(kotlin.Int){}[0] } final fun (kotlin.time/Duration.Companion).kotlinx.serialization.builtins/serializer(): kotlinx.serialization/KSerializer // kotlinx.serialization.builtins/serializer|serializer@kotlin.time.Duration.Companion(){}[0] +final fun (kotlin.uuid/Uuid.Companion).kotlinx.serialization.builtins/serializer(): kotlinx.serialization/KSerializer // kotlinx.serialization.builtins/serializer|serializer@kotlin.uuid.Uuid.Companion(){}[0] final fun (kotlin/Boolean.Companion).kotlinx.serialization.builtins/serializer(): kotlinx.serialization/KSerializer // kotlinx.serialization.builtins/serializer|serializer@kotlin.Boolean.Companion(){}[0] final fun (kotlin/Byte.Companion).kotlinx.serialization.builtins/serializer(): kotlinx.serialization/KSerializer // kotlinx.serialization.builtins/serializer|serializer@kotlin.Byte.Companion(){}[0] final fun (kotlin/Char.Companion).kotlinx.serialization.builtins/serializer(): kotlinx.serialization/KSerializer // kotlinx.serialization.builtins/serializer|serializer@kotlin.Char.Companion(){}[0] @@ -747,6 +748,12 @@ final object kotlinx.serialization.internal/UnitSerializer : kotlinx.serializati final val descriptor // kotlinx.serialization.internal/UnitSerializer.descriptor|{}descriptor[0] final fun (): kotlinx.serialization.descriptors/SerialDescriptor // kotlinx.serialization.internal/UnitSerializer.descriptor.|(){}[0] } +final object kotlinx.serialization.internal/UuidSerializer : kotlinx.serialization/KSerializer { // kotlinx.serialization.internal/UuidSerializer|null[0] + final fun deserialize(kotlinx.serialization.encoding/Decoder): kotlin.uuid/Uuid // kotlinx.serialization.internal/UuidSerializer.deserialize|deserialize(kotlinx.serialization.encoding.Decoder){}[0] + final fun serialize(kotlinx.serialization.encoding/Encoder, kotlin.uuid/Uuid) // kotlinx.serialization.internal/UuidSerializer.serialize|serialize(kotlinx.serialization.encoding.Encoder;kotlin.uuid.Uuid){}[0] + final val descriptor // kotlinx.serialization.internal/UuidSerializer.descriptor|{}descriptor[0] + final fun (): kotlinx.serialization.descriptors/SerialDescriptor // kotlinx.serialization.internal/UuidSerializer.descriptor.|(){}[0] +} final val kotlinx.serialization.builtins/nullable // kotlinx.serialization.builtins/nullable|@kotlinx.serialization.KSerializer<0:0>{0§}nullable[0] final fun <#A1: kotlin/Any> (kotlinx.serialization/KSerializer<#A1>).(): kotlinx.serialization/KSerializer<#A1?> // kotlinx.serialization.builtins/nullable.|@kotlinx.serialization.KSerializer<0:0>(){0§}[0] final val kotlinx.serialization.descriptors/capturedKClass // kotlinx.serialization.descriptors/capturedKClass|@kotlinx.serialization.descriptors.SerialDescriptor{}capturedKClass[0] @@ -871,7 +878,6 @@ sealed class <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin.coll abstract fun (#D).insertKeyValuePair(kotlin/Int, #A, #B) // kotlinx.serialization.internal/MapLikeSerializer.insertKeyValuePair|insertKeyValuePair@1:3(kotlin.Int;1:0;1:1){}[0] abstract val descriptor // kotlinx.serialization.internal/MapLikeSerializer.descriptor|{}descriptor[0] abstract fun (): kotlinx.serialization.descriptors/SerialDescriptor // kotlinx.serialization.internal/MapLikeSerializer.descriptor.|(){}[0] - constructor (kotlinx.serialization/KSerializer<#A>, kotlinx.serialization/KSerializer<#B>) // kotlinx.serialization.internal/MapLikeSerializer.|(kotlinx.serialization.KSerializer<1:0>;kotlinx.serialization.KSerializer<1:1>){}[0] final fun readAll(kotlinx.serialization.encoding/CompositeDecoder, #D, kotlin/Int, kotlin/Int) // kotlinx.serialization.internal/MapLikeSerializer.readAll|readAll(kotlinx.serialization.encoding.CompositeDecoder;1:3;kotlin.Int;kotlin.Int){}[0] final fun readElement(kotlinx.serialization.encoding/CompositeDecoder, kotlin/Int, #D, kotlin/Boolean) // kotlinx.serialization.internal/MapLikeSerializer.readElement|readElement(kotlinx.serialization.encoding.CompositeDecoder;kotlin.Int;1:3;kotlin.Boolean){}[0] final val keySerializer // kotlinx.serialization.internal/MapLikeSerializer.keySerializer|{}keySerializer[0] @@ -891,7 +897,6 @@ sealed class <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> kotlinx.seriali abstract fun readAll(kotlinx.serialization.encoding/CompositeDecoder, #C, kotlin/Int, kotlin/Int) // kotlinx.serialization.internal/AbstractCollectionSerializer.readAll|readAll(kotlinx.serialization.encoding.CompositeDecoder;1:2;kotlin.Int;kotlin.Int){}[0] abstract fun readElement(kotlinx.serialization.encoding/CompositeDecoder, kotlin/Int, #C, kotlin/Boolean = ...) // kotlinx.serialization.internal/AbstractCollectionSerializer.readElement|readElement(kotlinx.serialization.encoding.CompositeDecoder;kotlin.Int;1:2;kotlin.Boolean){}[0] abstract fun serialize(kotlinx.serialization.encoding/Encoder, #B) // kotlinx.serialization.internal/AbstractCollectionSerializer.serialize|serialize(kotlinx.serialization.encoding.Encoder;1:1){}[0] - constructor () // kotlinx.serialization.internal/AbstractCollectionSerializer.|(){}[0] final fun merge(kotlinx.serialization.encoding/Decoder, #B?): #B // kotlinx.serialization.internal/AbstractCollectionSerializer.merge|merge(kotlinx.serialization.encoding.Decoder;1:1?){}[0] open fun deserialize(kotlinx.serialization.encoding/Decoder): #B // kotlinx.serialization.internal/AbstractCollectionSerializer.deserialize|deserialize(kotlinx.serialization.encoding.Decoder){}[0] } @@ -899,7 +904,6 @@ sealed class <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> kotlinx.seriali abstract fun (#C).insert(kotlin/Int, #A) // kotlinx.serialization.internal/CollectionLikeSerializer.insert|insert@1:2(kotlin.Int;1:0){}[0] abstract val descriptor // kotlinx.serialization.internal/CollectionLikeSerializer.descriptor|{}descriptor[0] abstract fun (): kotlinx.serialization.descriptors/SerialDescriptor // kotlinx.serialization.internal/CollectionLikeSerializer.descriptor.|(){}[0] - constructor (kotlinx.serialization/KSerializer<#A>) // kotlinx.serialization.internal/CollectionLikeSerializer.|(kotlinx.serialization.KSerializer<1:0>){}[0] final fun readAll(kotlinx.serialization.encoding/CompositeDecoder, #C, kotlin/Int, kotlin/Int) // kotlinx.serialization.internal/CollectionLikeSerializer.readAll|readAll(kotlinx.serialization.encoding.CompositeDecoder;1:2;kotlin.Int;kotlin.Int){}[0] open fun readElement(kotlinx.serialization.encoding/CompositeDecoder, kotlin/Int, #C, kotlin/Boolean) // kotlinx.serialization.internal/CollectionLikeSerializer.readElement|readElement(kotlinx.serialization.encoding.CompositeDecoder;kotlin.Int;1:2;kotlin.Boolean){}[0] open fun serialize(kotlinx.serialization.encoding/Encoder, #B) // kotlinx.serialization.internal/CollectionLikeSerializer.serialize|serialize(kotlinx.serialization.encoding.Encoder;1:1){}[0] @@ -910,7 +914,6 @@ sealed class <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> kotlinx.seriali abstract fun (#C).(): #A // kotlinx.serialization.internal/KeyValueSerializer.key.|@1:2(){}[0] abstract val value // kotlinx.serialization.internal/KeyValueSerializer.value|@1:2{}value[0] abstract fun (#C).(): #B // kotlinx.serialization.internal/KeyValueSerializer.value.|@1:2(){}[0] - constructor (kotlinx.serialization/KSerializer<#A>, kotlinx.serialization/KSerializer<#B>) // kotlinx.serialization.internal/KeyValueSerializer.|(kotlinx.serialization.KSerializer<1:0>;kotlinx.serialization.KSerializer<1:1>){}[0] final val keySerializer // kotlinx.serialization.internal/KeyValueSerializer.keySerializer|{}keySerializer[0] final fun (): kotlinx.serialization/KSerializer<#A> // kotlinx.serialization.internal/KeyValueSerializer.keySerializer.|(){}[0] final val valueSerializer // kotlinx.serialization.internal/KeyValueSerializer.valueSerializer|{}valueSerializer[0] @@ -919,12 +922,10 @@ sealed class <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> kotlinx.seriali open fun serialize(kotlinx.serialization.encoding/Encoder, #C) // kotlinx.serialization.internal/KeyValueSerializer.serialize|serialize(kotlinx.serialization.encoding.Encoder;1:2){}[0] } sealed class kotlinx.serialization.descriptors/PolymorphicKind : kotlinx.serialization.descriptors/SerialKind { // kotlinx.serialization.descriptors/PolymorphicKind|null[0] - constructor () // kotlinx.serialization.descriptors/PolymorphicKind.|(){}[0] final object OPEN : kotlinx.serialization.descriptors/PolymorphicKind // kotlinx.serialization.descriptors/PolymorphicKind.OPEN|null[0] final object SEALED : kotlinx.serialization.descriptors/PolymorphicKind // kotlinx.serialization.descriptors/PolymorphicKind.SEALED|null[0] } sealed class kotlinx.serialization.descriptors/PrimitiveKind : kotlinx.serialization.descriptors/SerialKind { // kotlinx.serialization.descriptors/PrimitiveKind|null[0] - constructor () // kotlinx.serialization.descriptors/PrimitiveKind.|(){}[0] final object BOOLEAN : kotlinx.serialization.descriptors/PrimitiveKind // kotlinx.serialization.descriptors/PrimitiveKind.BOOLEAN|null[0] final object BYTE : kotlinx.serialization.descriptors/PrimitiveKind // kotlinx.serialization.descriptors/PrimitiveKind.BYTE|null[0] final object CHAR : kotlinx.serialization.descriptors/PrimitiveKind // kotlinx.serialization.descriptors/PrimitiveKind.CHAR|null[0] @@ -936,14 +937,12 @@ sealed class kotlinx.serialization.descriptors/PrimitiveKind : kotlinx.serializa final object STRING : kotlinx.serialization.descriptors/PrimitiveKind // kotlinx.serialization.descriptors/PrimitiveKind.STRING|null[0] } sealed class kotlinx.serialization.descriptors/SerialKind { // kotlinx.serialization.descriptors/SerialKind|null[0] - constructor () // kotlinx.serialization.descriptors/SerialKind.|(){}[0] final object CONTEXTUAL : kotlinx.serialization.descriptors/SerialKind // kotlinx.serialization.descriptors/SerialKind.CONTEXTUAL|null[0] final object ENUM : kotlinx.serialization.descriptors/SerialKind // kotlinx.serialization.descriptors/SerialKind.ENUM|null[0] open fun hashCode(): kotlin/Int // kotlinx.serialization.descriptors/SerialKind.hashCode|hashCode(){}[0] open fun toString(): kotlin/String // kotlinx.serialization.descriptors/SerialKind.toString|toString(){}[0] } sealed class kotlinx.serialization.descriptors/StructureKind : kotlinx.serialization.descriptors/SerialKind { // kotlinx.serialization.descriptors/StructureKind|null[0] - constructor () // kotlinx.serialization.descriptors/StructureKind.|(){}[0] final object CLASS : kotlinx.serialization.descriptors/StructureKind // kotlinx.serialization.descriptors/StructureKind.CLASS|null[0] final object LIST : kotlinx.serialization.descriptors/StructureKind // kotlinx.serialization.descriptors/StructureKind.LIST|null[0] final object MAP : kotlinx.serialization.descriptors/StructureKind // kotlinx.serialization.descriptors/StructureKind.MAP|null[0] @@ -954,7 +953,6 @@ sealed class kotlinx.serialization.modules/SerializersModule { // kotlinx.serial abstract fun <#A1: kotlin/Any> getPolymorphic(kotlin.reflect/KClass, #A1): kotlinx.serialization/SerializationStrategy<#A1>? // kotlinx.serialization.modules/SerializersModule.getPolymorphic|getPolymorphic(kotlin.reflect.KClass;0:0){0§}[0] abstract fun <#A1: kotlin/Any> getPolymorphic(kotlin.reflect/KClass, kotlin/String?): kotlinx.serialization/DeserializationStrategy<#A1>? // kotlinx.serialization.modules/SerializersModule.getPolymorphic|getPolymorphic(kotlin.reflect.KClass;kotlin.String?){0§}[0] abstract fun dumpTo(kotlinx.serialization.modules/SerializersModuleCollector) // kotlinx.serialization.modules/SerializersModule.dumpTo|dumpTo(kotlinx.serialization.modules.SerializersModuleCollector){}[0] - constructor () // kotlinx.serialization.modules/SerializersModule.|(){}[0] final fun <#A1: kotlin/Any> getContextual(kotlin.reflect/KClass<#A1>): kotlinx.serialization/KSerializer<#A1>? // kotlinx.serialization.modules/SerializersModule.getContextual|getContextual(kotlin.reflect.KClass<0:0>){0§}[0] } // Targets: [native, wasmJs, wasmWasi] diff --git a/core/commonMain/src/kotlinx/serialization/builtins/BuiltinSerializers.kt b/core/commonMain/src/kotlinx/serialization/builtins/BuiltinSerializers.kt index 4bd81012d..a593b49ef 100644 --- a/core/commonMain/src/kotlinx/serialization/builtins/BuiltinSerializers.kt +++ b/core/commonMain/src/kotlinx/serialization/builtins/BuiltinSerializers.kt @@ -10,6 +10,7 @@ import kotlinx.serialization.internal.* import kotlin.reflect.* import kotlinx.serialization.descriptors.* import kotlin.time.Duration +import kotlin.uuid.* /** * Returns a nullable serializer for the given serializer of non-null type. @@ -251,6 +252,20 @@ public fun UShort.Companion.serializer(): KSerializer = UShortSerializer */ public fun Duration.Companion.serializer(): KSerializer = DurationSerializer +/** + * Returns serializer for [Uuid]. + * Serializer operates with a standard UUID string representation, also known as "hex-and-dash" format — + * [RFC 9562 section 4](https://www.rfc-editor.org/rfc/rfc9562.html#section-4). + * + * Deserialization is case-insensitive. + * More details can be found in the documentation of [Uuid.toString] and [Uuid.parse] functions. + * + * @see Uuid.toString + * @see Uuid.parse + */ +@ExperimentalStdlibApi +public fun Uuid.Companion.serializer(): KSerializer = UuidSerializer + /** * Returns serializer for [Nothing]. * Throws an exception when trying to encode or decode. diff --git a/core/commonMain/src/kotlinx/serialization/internal/BuiltInSerializers.kt b/core/commonMain/src/kotlinx/serialization/internal/BuiltInSerializers.kt index 2e64a770f..74798f0f3 100644 --- a/core/commonMain/src/kotlinx/serialization/internal/BuiltInSerializers.kt +++ b/core/commonMain/src/kotlinx/serialization/internal/BuiltInSerializers.kt @@ -10,6 +10,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlin.time.Duration +import kotlin.uuid.* @PublishedApi @@ -37,3 +38,17 @@ internal object NothingSerializer : KSerializer { throw SerializationException("'kotlin.Nothing' does not have instances") } } + +@PublishedApi +@ExperimentalStdlibApi +internal object UuidSerializer: KSerializer { + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("kotlin.uuid.Uuid", PrimitiveKind.STRING) + + override fun serialize(encoder: Encoder, value: Uuid) { + encoder.encodeString(value.toString()) + } + + override fun deserialize(decoder: Decoder): Uuid { + return Uuid.parse(decoder.decodeString()) + } +} diff --git a/core/commonMain/src/kotlinx/serialization/internal/Primitives.kt b/core/commonMain/src/kotlinx/serialization/internal/Primitives.kt index 2d9c52852..b0885a55d 100644 --- a/core/commonMain/src/kotlinx/serialization/internal/Primitives.kt +++ b/core/commonMain/src/kotlinx/serialization/internal/Primitives.kt @@ -11,11 +11,11 @@ import kotlinx.serialization.* import kotlinx.serialization.builtins.* import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.* -import kotlin.native.concurrent.* import kotlin.reflect.* import kotlin.time.Duration +import kotlin.uuid.Uuid -@OptIn(ExperimentalUnsignedTypes::class) +@OptIn(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class) private val BUILTIN_SERIALIZERS = mapOf( String::class to String.serializer(), Char::class to Char.serializer(), @@ -44,7 +44,8 @@ private val BUILTIN_SERIALIZERS = mapOf( BooleanArray::class to BooleanArraySerializer(), Unit::class to Unit.serializer(), Nothing::class to NothingSerializer(), - Duration::class to Duration.serializer() + Duration::class to Duration.serializer(), + Uuid::class to Uuid.serializer() ) internal class PrimitiveSerialDescriptor( diff --git a/formats/cbor/api/kotlinx-serialization-cbor.klib.api b/formats/cbor/api/kotlinx-serialization-cbor.klib.api index 0064161ac..daa407aab 100644 --- a/formats/cbor/api/kotlinx-serialization-cbor.klib.api +++ b/formats/cbor/api/kotlinx-serialization-cbor.klib.api @@ -22,7 +22,6 @@ open annotation class kotlinx.serialization.cbor/ByteString : kotlin/Annotation constructor () // kotlinx.serialization.cbor/ByteString.|(){}[0] } sealed class kotlinx.serialization.cbor/Cbor : kotlinx.serialization/BinaryFormat { // kotlinx.serialization.cbor/Cbor|null[0] - constructor (kotlin/Boolean, kotlin/Boolean, kotlinx.serialization.modules/SerializersModule) // kotlinx.serialization.cbor/Cbor.|(kotlin.Boolean;kotlin.Boolean;kotlinx.serialization.modules.SerializersModule){}[0] final object Default : kotlinx.serialization.cbor/Cbor // kotlinx.serialization.cbor/Cbor.Default|null[0] open fun <#A1: kotlin/Any?> decodeFromByteArray(kotlinx.serialization/DeserializationStrategy<#A1>, kotlin/ByteArray): #A1 // kotlinx.serialization.cbor/Cbor.decodeFromByteArray|decodeFromByteArray(kotlinx.serialization.DeserializationStrategy<0:0>;kotlin.ByteArray){0§}[0] open fun <#A1: kotlin/Any?> encodeToByteArray(kotlinx.serialization/SerializationStrategy<#A1>, #A1): kotlin/ByteArray // kotlinx.serialization.cbor/Cbor.encodeToByteArray|encodeToByteArray(kotlinx.serialization.SerializationStrategy<0:0>;0:0){0§}[0] diff --git a/formats/json-tests/build.gradle.kts b/formats/json-tests/build.gradle.kts index 53a57f003..4166f0c98 100644 --- a/formats/json-tests/build.gradle.kts +++ b/formats/json-tests/build.gradle.kts @@ -26,6 +26,7 @@ kotlin { sourceSets { configureEach { languageSettings { + optIn("kotlin.ExperimentalStdlibApi") optIn("kotlinx.serialization.internal.CoreFriendModuleApi") optIn("kotlinx.serialization.json.internal.JsonFriendModuleApi") } diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt index 4b4aebfd2..6aebee901 100644 --- a/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/SerializersLookupTest.kt @@ -15,6 +15,7 @@ import kotlinx.serialization.test.* import kotlin.reflect.* import kotlin.test.* import kotlin.time.Duration +import kotlin.uuid.* @Suppress("RemoveExplicitTypeArguments") // This is exactly what's being tested class SerializersLookupTest : JsonTestBase() { @@ -141,6 +142,13 @@ class SerializersLookupTest : JsonTestBase() { assertSame(Duration.serializer(), serializer()) } + @Test + fun testLookupUuid() { + assertSame?>(Uuid.serializer(), serializerOrNull(typeOf())) + // TODO: uncomment in 2.1 release +// assertSame?>(Uuid.serializer(), serializer()) + } + @Test fun testCustomGeneric() { val intBox = Box(42) diff --git a/formats/json-tests/commonTest/src/kotlinx/serialization/features/UuidTest.kt b/formats/json-tests/commonTest/src/kotlinx/serialization/features/UuidTest.kt new file mode 100644 index 000000000..52f3b13d9 --- /dev/null +++ b/formats/json-tests/commonTest/src/kotlinx/serialization/features/UuidTest.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +package kotlinx.serialization.features + +import kotlinx.serialization.* +import kotlinx.serialization.builtins.* +import kotlinx.serialization.json.* +import kotlinx.serialization.modules.* +import kotlin.test.* +import kotlin.uuid.* + +class UuidTest : JsonTestBase() { + @Test + fun testPlainUuid() { + val uuid = Uuid.random() + assertJsonFormAndRestored(Uuid.serializer(), uuid, "\"$uuid\"") + } + + // TODO: write a test without @Contextual after 2.1.0 release + @Serializable + data class Holder(@Contextual val uuid: Uuid) + + val json = Json { serializersModule = serializersModuleOf(Uuid.serializer()) } + + @Test + fun testNested() { + val fixed = Uuid.parse("bc501c76-d806-4578-b45e-97a264e280f1") + assertJsonFormAndRestored( + Holder.serializer(), + Holder(fixed), + """{"uuid":"bc501c76-d806-4578-b45e-97a264e280f1"}""", + json + ) + } +} diff --git a/formats/json/api/kotlinx-serialization-json.klib.api b/formats/json/api/kotlinx-serialization-json.klib.api index 6026f81f6..6993e759d 100644 --- a/formats/json/api/kotlinx-serialization-json.klib.api +++ b/formats/json/api/kotlinx-serialization-json.klib.api @@ -357,7 +357,6 @@ open annotation class kotlinx.serialization.json/JsonNames : kotlin/Annotation { final fun (): kotlin/Array // kotlinx.serialization.json/JsonNames.names.|(){}[0] } sealed class kotlinx.serialization.json/Json : kotlinx.serialization/StringFormat { // kotlinx.serialization.json/Json|null[0] - constructor (kotlinx.serialization.json/JsonConfiguration, kotlinx.serialization.modules/SerializersModule) // kotlinx.serialization.json/Json.|(kotlinx.serialization.json.JsonConfiguration;kotlinx.serialization.modules.SerializersModule){}[0] final fun <#A1: kotlin/Any?> decodeFromJsonElement(kotlinx.serialization/DeserializationStrategy<#A1>, kotlinx.serialization.json/JsonElement): #A1 // kotlinx.serialization.json/Json.decodeFromJsonElement|decodeFromJsonElement(kotlinx.serialization.DeserializationStrategy<0:0>;kotlinx.serialization.json.JsonElement){0§}[0] final fun <#A1: kotlin/Any?> decodeFromString(kotlinx.serialization/DeserializationStrategy<#A1>, kotlin/String): #A1 // kotlinx.serialization.json/Json.decodeFromString|decodeFromString(kotlinx.serialization.DeserializationStrategy<0:0>;kotlin.String){0§}[0] final fun <#A1: kotlin/Any?> encodeToJsonElement(kotlinx.serialization/SerializationStrategy<#A1>, #A1): kotlinx.serialization.json/JsonElement // kotlinx.serialization.json/Json.encodeToJsonElement|encodeToJsonElement(kotlinx.serialization.SerializationStrategy<0:0>;0:0){0§}[0] @@ -371,7 +370,6 @@ sealed class kotlinx.serialization.json/Json : kotlinx.serialization/StringForma open fun (): kotlinx.serialization.modules/SerializersModule // kotlinx.serialization.json/Json.serializersModule.|(){}[0] } sealed class kotlinx.serialization.json/JsonElement { // kotlinx.serialization.json/JsonElement|null[0] - constructor () // kotlinx.serialization.json/JsonElement.|(){}[0] final object Companion { // kotlinx.serialization.json/JsonElement.Companion|null[0] final fun serializer(): kotlinx.serialization/KSerializer // kotlinx.serialization.json/JsonElement.Companion.serializer|serializer(){}[0] } @@ -381,7 +379,6 @@ sealed class kotlinx.serialization.json/JsonPrimitive : kotlinx.serialization.js abstract fun (): kotlin/String // kotlinx.serialization.json/JsonPrimitive.content.|(){}[0] abstract val isString // kotlinx.serialization.json/JsonPrimitive.isString|{}isString[0] abstract fun (): kotlin/Boolean // kotlinx.serialization.json/JsonPrimitive.isString.|(){}[0] - constructor () // kotlinx.serialization.json/JsonPrimitive.|(){}[0] final object Companion { // kotlinx.serialization.json/JsonPrimitive.Companion|null[0] final fun serializer(): kotlinx.serialization/KSerializer // kotlinx.serialization.json/JsonPrimitive.Companion.serializer|serializer(){}[0] } diff --git a/formats/properties/api/kotlinx-serialization-properties.klib.api b/formats/properties/api/kotlinx-serialization-properties.klib.api index e60362384..39f83f96c 100644 --- a/formats/properties/api/kotlinx-serialization-properties.klib.api +++ b/formats/properties/api/kotlinx-serialization-properties.klib.api @@ -12,7 +12,6 @@ final inline fun <#A: reified kotlin/Any?> (kotlinx.serialization.properties/Pro final inline fun <#A: reified kotlin/Any?> (kotlinx.serialization.properties/Properties).kotlinx.serialization.properties/encodeToMap(#A): kotlin.collections/Map // kotlinx.serialization.properties/encodeToMap|encodeToMap@kotlinx.serialization.properties.Properties(0:0){0§}[0] final inline fun <#A: reified kotlin/Any?> (kotlinx.serialization.properties/Properties).kotlinx.serialization.properties/encodeToStringMap(#A): kotlin.collections/Map // kotlinx.serialization.properties/encodeToStringMap|encodeToStringMap@kotlinx.serialization.properties.Properties(0:0){0§}[0] sealed class kotlinx.serialization.properties/Properties : kotlinx.serialization/SerialFormat { // kotlinx.serialization.properties/Properties|null[0] - constructor (kotlinx.serialization.modules/SerializersModule, kotlin/Nothing?) // kotlinx.serialization.properties/Properties.|(kotlinx.serialization.modules.SerializersModule;kotlin.Nothing?){}[0] final fun <#A1: kotlin/Any?> decodeFromMap(kotlinx.serialization/DeserializationStrategy<#A1>, kotlin.collections/Map): #A1 // kotlinx.serialization.properties/Properties.decodeFromMap|decodeFromMap(kotlinx.serialization.DeserializationStrategy<0:0>;kotlin.collections.Map){0§}[0] final fun <#A1: kotlin/Any?> decodeFromStringMap(kotlinx.serialization/DeserializationStrategy<#A1>, kotlin.collections/Map): #A1 // kotlinx.serialization.properties/Properties.decodeFromStringMap|decodeFromStringMap(kotlinx.serialization.DeserializationStrategy<0:0>;kotlin.collections.Map){0§}[0] final fun <#A1: kotlin/Any?> encodeToMap(kotlinx.serialization/SerializationStrategy<#A1>, #A1): kotlin.collections/Map // kotlinx.serialization.properties/Properties.encodeToMap|encodeToMap(kotlinx.serialization.SerializationStrategy<0:0>;0:0){0§}[0] diff --git a/formats/protobuf/api/kotlinx-serialization-protobuf.klib.api b/formats/protobuf/api/kotlinx-serialization-protobuf.klib.api index c5cf553bc..df717cbf9 100644 --- a/formats/protobuf/api/kotlinx-serialization-protobuf.klib.api +++ b/formats/protobuf/api/kotlinx-serialization-protobuf.klib.api @@ -45,7 +45,6 @@ open annotation class kotlinx.serialization.protobuf/ProtoType : kotlin/Annotati final fun (): kotlinx.serialization.protobuf/ProtoIntegerType // kotlinx.serialization.protobuf/ProtoType.type.|(){}[0] } sealed class kotlinx.serialization.protobuf/ProtoBuf : kotlinx.serialization/BinaryFormat { // kotlinx.serialization.protobuf/ProtoBuf|null[0] - constructor (kotlin/Boolean, kotlinx.serialization.modules/SerializersModule) // kotlinx.serialization.protobuf/ProtoBuf.|(kotlin.Boolean;kotlinx.serialization.modules.SerializersModule){}[0] final object Default : kotlinx.serialization.protobuf/ProtoBuf // kotlinx.serialization.protobuf/ProtoBuf.Default|null[0] open fun <#A1: kotlin/Any?> decodeFromByteArray(kotlinx.serialization/DeserializationStrategy<#A1>, kotlin/ByteArray): #A1 // kotlinx.serialization.protobuf/ProtoBuf.decodeFromByteArray|decodeFromByteArray(kotlinx.serialization.DeserializationStrategy<0:0>;kotlin.ByteArray){0§}[0] open fun <#A1: kotlin/Any?> encodeToByteArray(kotlinx.serialization/SerializationStrategy<#A1>, #A1): kotlin/ByteArray // kotlinx.serialization.protobuf/ProtoBuf.encodeToByteArray|encodeToByteArray(kotlinx.serialization.SerializationStrategy<0:0>;0:0){0§}[0] diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c82a83d6b..013228038 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlin = "2.0.0" +kotlin = "2.0.20-Beta2" kover = "0.8.2" dokka = "1.9.20" knit = "0.5.0" diff --git a/integration-test/gradle.properties b/integration-test/gradle.properties index 6917df662..317291a31 100644 --- a/integration-test/gradle.properties +++ b/integration-test/gradle.properties @@ -2,7 +2,7 @@ # Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. # -mainKotlinVersion=2.0.0 +mainKotlinVersion=2.0.20-Beta2 mainLibVersion=1.7.2-SNAPSHOT kotlin.code.style=official