summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVsevolod Tolstopyatov <qwwdfsad@gmail.com>2020-07-08 18:07:58 +0300
committerVsevolod Tolstopyatov <qwwdfsad@gmail.com>2020-07-12 12:50:57 -0700
commite772f37367c252e59ab08b0b4c7613f0d8053d9d (patch)
treed14c63e8882412717cbb688a6637db71b5720aa0
parent5a991a6d6e768e678eefba159796aef0a4a8b396 (diff)
downloadkotlinx.serialization-e772f37367c252e59ab08b0b4c7613f0d8053d9d.tar.gz
[API stabilization] Encoder and Decoder
* Deprecate potentially dangerous extensions * Rename context to serializersModule to align with modules rework * Remove decode/encodeUnit * Rename READ_DONE to DECODE_DONE
-rw-r--r--formats/cbor/commonMain/src/kotlinx/serialization/cbor/Cbor.kt15
-rw-r--r--formats/config/src/main/kotlin/kotlinx/serialization/config/ConfigReader.kt14
-rw-r--r--formats/properties/commonMain/src/kotlinx/serialization/Properties.kt21
-rw-r--r--formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/ProtoBuf.kt15
-rw-r--r--formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufTaggedDecoder.kt8
-rw-r--r--formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufTaggedEncoder.kt8
-rw-r--r--integration-test/src/commonTest/kotlin/sample/BasicTypesSerializationTest.kt6
-rw-r--r--runtime/api/kotlinx-serialization-runtime.api38
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/ContextSerializer.kt4
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/Decoding.kt58
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/Encoding.kt32
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/KSerializer.kt2
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/Migrations.kt24
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/encoding/AbstractDecoder.kt5
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/encoding/AbstractEncoder.kt7
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/internal/AbstractPolymorphicSerializer.kt8
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/internal/CollectionSerializers.kt3
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/internal/Tagged.kt29
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/internal/Tuples.kt4
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/json/Json.kt4
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/json/JsonParametricSerializer.kt2
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt10
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt2
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/json/internal/TreeJsonInput.kt16
-rw-r--r--runtime/commonMain/src/kotlinx/serialization/json/internal/TreeJsonOutput.kt4
-rw-r--r--runtime/commonTest/src/kotlinx/serialization/BasicTypesSerializationTest.kt7
-rw-r--r--runtime/commonTest/src/kotlinx/serialization/TaggedTest.kt7
-rw-r--r--runtime/commonTest/src/kotlinx/serialization/UnknownElementIndexTest.kt2
-rw-r--r--runtime/commonTest/src/kotlinx/serialization/features/BinaryPayloadExampleTest.kt2
-rw-r--r--runtime/commonTest/src/kotlinx/serialization/features/GenericCustomSerializerTest.kt2
-rw-r--r--runtime/commonTest/src/kotlinx/serialization/json/MapLikeSerializerTest.kt2
-rw-r--r--runtime/jsMain/src/kotlinx/serialization/DynamicObjectParser.kt11
-rw-r--r--runtime/jsMain/src/kotlinx/serialization/DynamicObjectSerializer.kt4
-rw-r--r--runtime/jvmTest/src/kotlinx/serialization/SerializationMethodInvocationOrderTest.kt4
-rw-r--r--runtime/jvmTest/src/kotlinx/serialization/SerializeFlatTest.kt26
-rw-r--r--runtime/jvmTest/src/kotlinx/serialization/privateclasstest/PrivateDataOutOfKotlinXSerializationPackageTest.kt4
36 files changed, 168 insertions, 242 deletions
diff --git a/formats/cbor/commonMain/src/kotlinx/serialization/cbor/Cbor.kt b/formats/cbor/commonMain/src/kotlinx/serialization/cbor/Cbor.kt
index ccb0c1c3..291919e0 100644
--- a/formats/cbor/commonMain/src/kotlinx/serialization/cbor/Cbor.kt
+++ b/formats/cbor/commonMain/src/kotlinx/serialization/cbor/Cbor.kt
@@ -5,7 +5,8 @@
package kotlinx.serialization.cbor
import kotlinx.serialization.*
-import kotlinx.serialization.CompositeDecoder.Companion.READ_DONE
+import kotlinx.serialization.CompositeDecoder.Companion.DECODE_DONE
+import kotlinx.serialization.builtins.*
import kotlinx.serialization.cbor.internal.ByteArrayInput
import kotlinx.serialization.cbor.internal.ByteArrayOutput
import kotlinx.serialization.encoding.*
@@ -45,7 +46,7 @@ public class Cbor(
// Writes class as map [fieldName, fieldValue]
private open inner class CborWriter(val encoder: CborEncoder) : AbstractEncoder() {
- override val context: SerialModule
+ override val serializersModule: SerialModule
get() = this@Cbor.context
override fun shouldEncodeElementDefault(descriptor: SerialDescriptor, index: Int): Boolean = encodeDefaults
@@ -169,7 +170,7 @@ public class Cbor(
override fun skipBeginToken() = setSize(decoder.startArray())
- override fun decodeElementIndex(descriptor: SerialDescriptor) = if (!finiteMode && decoder.isEnd() || (finiteMode && ind >= size)) READ_DONE else ind++
+ override fun decodeElementIndex(descriptor: SerialDescriptor) = if (!finiteMode && decoder.isEnd() || (finiteMode && ind >= size)) DECODE_DONE else ind++
}
private open inner class CborReader(val decoder: CborDecoder) : AbstractDecoder() {
@@ -187,7 +188,7 @@ public class Cbor(
}
}
- override val context: SerialModule
+ override val serializersModule: SerialModule
get() = this@Cbor.context
protected open fun skipBeginToken() = setSize(decoder.startMap())
@@ -207,7 +208,7 @@ public class Cbor(
}
override fun decodeElementIndex(descriptor: SerialDescriptor): Int {
- if (!finiteMode && decoder.isEnd() || (finiteMode && readProperties >= size)) return READ_DONE
+ if (!finiteMode && decoder.isEnd() || (finiteMode && readProperties >= size)) return DECODE_DONE
val elemName = decoder.nextString()
readProperties++
return descriptor.getElementIndexOrThrow(elemName)
@@ -396,13 +397,13 @@ public class Cbor(
override fun <T> encodeToByteArray(serializer: SerializationStrategy<T>, value: T): ByteArray {
val output = ByteArrayOutput()
val dumper = CborWriter(CborEncoder(output))
- dumper.encode(serializer, value)
+ dumper.encodeSerializableValue(serializer, value)
return output.toByteArray()
}
override fun <T> decodeFromByteArray(deserializer: DeserializationStrategy<T>, bytes: ByteArray): T {
val stream = ByteArrayInput(bytes)
val reader = CborReader(CborDecoder(stream))
- return reader.decode(deserializer)
+ return reader.decodeSerializableValue(deserializer)
}
}
diff --git a/formats/config/src/main/kotlin/kotlinx/serialization/config/ConfigReader.kt b/formats/config/src/main/kotlin/kotlinx/serialization/config/ConfigReader.kt
index 65187ea3..0be9ca7b 100644
--- a/formats/config/src/main/kotlin/kotlinx/serialization/config/ConfigReader.kt
+++ b/formats/config/src/main/kotlin/kotlinx/serialization/config/ConfigReader.kt
@@ -6,16 +6,16 @@ package kotlinx.serialization.config
import com.typesafe.config.*
import kotlinx.serialization.*
-import kotlinx.serialization.CompositeDecoder.Companion.READ_DONE
import kotlinx.serialization.internal.*
import kotlinx.serialization.modules.*
+import kotlinx.serialization.CompositeDecoder.Companion.DECODE_DONE
private val SerialKind.listLike get() = this == StructureKind.LIST || this is PolymorphicKind
private val SerialKind.objLike get() = this == StructureKind.CLASS || this == StructureKind.OBJECT
/**
* Allows [deserialization][parse]
- * of [Config] object from popular Lighbend/config library into Kotlin objects.
+ * of [Config] object from popular Lightbend/config library into Kotlin objects.
*
* [Config] object represents "Human-Optimized Config Object Notation" —
* [HOCON][https://github.com/lightbend/config#using-hocon-the-json-superset].
@@ -32,11 +32,11 @@ public class ConfigParser(
public inline fun <reified T : Any> parse(conf: Config): T = parse(conf, context.getContextualOrDefault())
public fun <T> parse(conf: Config, deserializer: DeserializationStrategy<T>): T =
- ConfigReader(conf).decode(deserializer)
+ ConfigReader(conf).decodeSerializableValue(deserializer)
private abstract inner class ConfigConverter<T> : TaggedDecoder<T>() {
- override val context: SerialModule
+ override val serializersModule: SerialModule
get() = this@ConfigParser.context
abstract fun getTaggedConfigValue(tag: T): ConfigValue
@@ -84,7 +84,7 @@ public class ConfigParser(
return ind
}
}
- return READ_DONE
+ return DECODE_DONE
}
private fun composeName(parentName: String, childName: String) =
@@ -131,7 +131,7 @@ public class ConfigParser(
override fun decodeElementIndex(descriptor: SerialDescriptor): Int {
ind++
- return if (ind > list.size - 1) READ_DONE else ind
+ return if (ind > list.size - 1) DECODE_DONE else ind
}
override fun getTaggedConfigValue(tag: Int): ConfigValue = list[tag]
@@ -163,7 +163,7 @@ public class ConfigParser(
override fun decodeElementIndex(descriptor: SerialDescriptor): Int {
ind++
- return if (ind >= indexSize) READ_DONE else ind
+ return if (ind >= indexSize) CompositeDecoder.DECODE_DONE else ind
}
override fun getTaggedConfigValue(tag: Int): ConfigValue {
diff --git a/formats/properties/commonMain/src/kotlinx/serialization/Properties.kt b/formats/properties/commonMain/src/kotlinx/serialization/Properties.kt
index 0a75f79f..54d4b1b0 100644
--- a/formats/properties/commonMain/src/kotlinx/serialization/Properties.kt
+++ b/formats/properties/commonMain/src/kotlinx/serialization/Properties.kt
@@ -4,7 +4,6 @@
package kotlinx.serialization
-import kotlinx.serialization.CompositeDecoder.Companion.READ_DONE
import kotlinx.serialization.internal.*
import kotlinx.serialization.modules.*
@@ -39,7 +38,7 @@ import kotlinx.serialization.modules.*
public class Properties(override val context: SerialModule = EmptyModule) : SerialFormat {
private inner class OutMapper : NamedValueEncoder() {
- override val context: SerialModule = this@Properties.context
+ override val serializersModule: SerialModule = this@Properties.context
internal val map: MutableMap<String, Any> = mutableMapOf()
@@ -64,7 +63,7 @@ public class Properties(override val context: SerialModule = EmptyModule) : Seri
}
private inner class OutNullableMapper : NamedValueEncoder() {
- override val context: SerialModule = this@Properties.context
+ override val serializersModule: SerialModule = this@Properties.context
internal val map: MutableMap<String, Any?> = mutableMapOf()
@@ -87,7 +86,7 @@ public class Properties(override val context: SerialModule = EmptyModule) : Seri
}
private inner class InMapper(private val map: Map<String, Any>) : NamedValueDecoder() {
- override val context: SerialModule = this@Properties.context
+ override val serializersModule: SerialModule = this@Properties.context
private var currentIndex = 0
@@ -118,12 +117,12 @@ public class Properties(override val context: SerialModule = EmptyModule) : Seri
val name = descriptor.getTag(currentIndex++)
if (map.keys.any { it.startsWith(name) }) return currentIndex - 1
}
- return READ_DONE
+ return CompositeDecoder.DECODE_DONE
}
}
private inner class InNullableMapper(val map: Map<String, Any?>) : NamedValueDecoder() {
- override val context: SerialModule = this@Properties.context
+ override val serializersModule: SerialModule = this@Properties.context
private var currentIndex = 0
@@ -142,7 +141,7 @@ public class Properties(override val context: SerialModule = EmptyModule) : Seri
val name = descriptor.getTag(currentIndex++)
if (map.keys.any { it.startsWith(name) }) return currentIndex - 1
}
- return READ_DONE
+ return CompositeDecoder.DECODE_DONE
}
override fun decodeTaggedValue(tag: String): Any = map.getValue(tag)!!
@@ -169,7 +168,7 @@ public class Properties(override val context: SerialModule = EmptyModule) : Seri
*/
public fun <T> store(strategy: SerializationStrategy<T>, value: T): Map<String, Any> {
val m = OutMapper()
- m.encode(strategy, value)
+ m.encodeSerializableValue(strategy, value)
return m.map
}
@@ -179,7 +178,7 @@ public class Properties(override val context: SerialModule = EmptyModule) : Seri
*/
public fun <T> storeNullable(strategy: SerializationStrategy<T>, value: T): Map<String, Any?> {
val m = OutNullableMapper()
- m.encode(strategy, value)
+ m.encodeSerializableValue(strategy, value)
return m.map
}
@@ -189,7 +188,7 @@ public class Properties(override val context: SerialModule = EmptyModule) : Seri
*/
public fun <T> load(strategy: DeserializationStrategy<T>, map: Map<String, Any>): T {
val m = InMapper(map)
- return m.decode(strategy)
+ return m.decodeSerializableValue(strategy)
}
/**
@@ -198,7 +197,7 @@ public class Properties(override val context: SerialModule = EmptyModule) : Seri
*/
public fun <T> loadNullable(strategy: DeserializationStrategy<T>, map: Map<String, Any?>): T {
val m = InNullableMapper(map)
- return m.decode(strategy)
+ return m.decodeSerializableValue(strategy)
}
/**
diff --git a/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/ProtoBuf.kt b/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/ProtoBuf.kt
index e0c1ae31..112160ee 100644
--- a/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/ProtoBuf.kt
+++ b/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/ProtoBuf.kt
@@ -5,7 +5,6 @@
package kotlinx.serialization.protobuf
import kotlinx.serialization.*
-import kotlinx.serialization.CompositeDecoder.Companion.READ_DONE
import kotlinx.serialization.builtins.*
import kotlinx.serialization.internal.*
import kotlinx.serialization.modules.*
@@ -125,7 +124,7 @@ public class ProtoBuf(
private val writer: ProtobufWriter,
@JvmField val descriptor: SerialDescriptor
) : ProtobufTaggedEncoder() {
- public override val context
+ public override val serializersModule
get() = this@ProtoBuf.context
override fun shouldEncodeElementDefault(descriptor: SerialDescriptor, index: Int): Boolean = encodeDefaults
@@ -295,7 +294,7 @@ public class ProtoBuf(
@JvmField val reader: ProtobufReader,
@JvmField val descriptor: SerialDescriptor
) : ProtobufTaggedDecoder() {
- override val context: SerialModule
+ override val serializersModule: SerialModule
get() = this@ProtoBuf.context
// Proto id -> index in serial descriptor cache
@@ -475,7 +474,7 @@ public class ProtoBuf(
while (true) {
val protoId = reader.readTag()
if (protoId == -1) { // EOF
- return READ_DONE
+ return CompositeDecoder.DECODE_DONE
}
val index = getIndexByTag(protoId)
if (index == -1) { // not found
@@ -523,7 +522,7 @@ public class ProtoBuf(
private fun decodeListIndexNoTag(): Int {
val size = -tagOrSize
val idx = ++index
- if (idx.toLong() == size) return READ_DONE
+ if (idx.toLong() == size) return CompositeDecoder.DECODE_DONE
return idx
}
@@ -540,7 +539,7 @@ public class ProtoBuf(
} else {
// If we read tag of a different message, push it back to the reader and bail out
reader.pushBackTag()
- READ_DONE
+ CompositeDecoder.DECODE_DONE
}
}
@@ -583,13 +582,13 @@ public class ProtoBuf(
override fun <T> encodeToByteArray(serializer: SerializationStrategy<T>, value: T): ByteArray {
val output = ByteArrayOutput()
val encoder = ProtobufEncoder(ProtobufWriter(output), serializer.descriptor)
- encoder.encode(serializer, value)
+ encoder.encodeSerializableValue(serializer, value)
return output.toByteArray()
}
override fun <T> decodeFromByteArray(deserializer: DeserializationStrategy<T>, bytes: ByteArray): T {
val input = ByteArrayInput(bytes)
val decoder = ProtobufDecoder(ProtobufReader(input), deserializer.descriptor)
- return decoder.decode(deserializer)
+ return decoder.decodeSerializableValue(deserializer)
}
}
diff --git a/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufTaggedDecoder.kt b/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufTaggedDecoder.kt
index 474fdb98..499235d2 100644
--- a/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufTaggedDecoder.kt
+++ b/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufTaggedDecoder.kt
@@ -92,12 +92,4 @@ internal abstract class ProtobufTaggedDecoder : ProtobufTaggedBase(), Decoder, C
decodeNull()
}
}
-
- override fun decodeUnit() {
- error("Should not be called")
- }
-
- override fun decodeUnitElement(descriptor: SerialDescriptor, index: Int) {
- error("Should not be called")
- }
}
diff --git a/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufTaggedEncoder.kt b/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufTaggedEncoder.kt
index 73cab91c..b8ea1970 100644
--- a/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufTaggedEncoder.kt
+++ b/formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufTaggedEncoder.kt
@@ -129,12 +129,4 @@ internal abstract class ProtobufTaggedEncoder : ProtobufTaggedBase(), Encoder, C
pushTag(descriptor.getTag(index))
encodeNullableSerializableValue(serializer, value)
}
-
- override fun encodeUnit() {
- error("Should not be called")
- }
-
- override fun encodeUnitElement(descriptor: SerialDescriptor, index: Int) {
- error("Should not be called")
- }
}
diff --git a/integration-test/src/commonTest/kotlin/sample/BasicTypesSerializationTest.kt b/integration-test/src/commonTest/kotlin/sample/BasicTypesSerializationTest.kt
index 45f806e0..0f76812d 100644
--- a/integration-test/src/commonTest/kotlin/sample/BasicTypesSerializationTest.kt
+++ b/integration-test/src/commonTest/kotlin/sample/BasicTypesSerializationTest.kt
@@ -137,7 +137,7 @@ class BasicTypesSerializationTest {
inp.skipWhitespace(',')
val name = inp.nextUntil(':', '}')
if (name.isEmpty())
- return READ_DONE
+ return CompositeDecoder.DECODE_DONE
val index = desc.getElementIndexOrThrow(name)
inp.expect(':')
return index
@@ -228,11 +228,11 @@ class BasicTypesSerializationTest {
// serialize to string
val sb = StringBuilder()
val out = KeyValueOutput(sb)
- out.encode(TypesUmbrella.serializer(), data)
+ out.encodeSerializableValue(TypesUmbrella.serializer(), data)
// deserialize from string
val str = sb.toString()
val inp = KeyValueInput(Parser(StringReader(str)))
- val other = inp.decode(TypesUmbrella.serializer())
+ val other = inp.decodeSerializableValue(TypesUmbrella.serializer())
// assert we've got it back from string
assertEquals(data, other)
assertNotSame(data, other)
diff --git a/runtime/api/kotlinx-serialization-runtime.api b/runtime/api/kotlinx-serialization-runtime.api
index e7beec7f..5e331de9 100644
--- a/runtime/api/kotlinx-serialization-runtime.api
+++ b/runtime/api/kotlinx-serialization-runtime.api
@@ -10,6 +10,7 @@ public abstract interface class kotlinx/serialization/BinaryFormat : kotlinx/ser
public abstract interface class kotlinx/serialization/CompositeDecoder {
public static final field Companion Lkotlinx/serialization/CompositeDecoder$Companion;
+ public static final field DECODE_DONE I
public static final field READ_ALL I
public static final field READ_DONE I
public static final field UNKNOWN_NAME I
@@ -29,15 +30,15 @@ public abstract interface class kotlinx/serialization/CompositeDecoder {
public abstract fun decodeSerializableElement (Lkotlinx/serialization/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
public abstract fun decodeShortElement (Lkotlinx/serialization/SerialDescriptor;I)S
public abstract fun decodeStringElement (Lkotlinx/serialization/SerialDescriptor;I)Ljava/lang/String;
- public abstract fun decodeUnitElement (Lkotlinx/serialization/SerialDescriptor;I)V
public abstract fun endStructure (Lkotlinx/serialization/SerialDescriptor;)V
- public abstract fun getContext ()Lkotlinx/serialization/modules/SerialModule;
+ public abstract fun getSerializersModule ()Lkotlinx/serialization/modules/SerialModule;
public abstract fun getUpdateMode ()Lkotlinx/serialization/UpdateMode;
public abstract fun updateNullableSerializableElement (Lkotlinx/serialization/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
public abstract fun updateSerializableElement (Lkotlinx/serialization/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
}
public final class kotlinx/serialization/CompositeDecoder$Companion {
+ public static final field DECODE_DONE I
public static final field READ_ALL I
public static final field READ_DONE I
public static final field UNKNOWN_NAME I
@@ -70,9 +71,8 @@ public abstract interface class kotlinx/serialization/CompositeEncoder {
public abstract fun encodeSerializableElement (Lkotlinx/serialization/SerialDescriptor;ILkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V
public abstract fun encodeShortElement (Lkotlinx/serialization/SerialDescriptor;IS)V
public abstract fun encodeStringElement (Lkotlinx/serialization/SerialDescriptor;ILjava/lang/String;)V
- public abstract fun encodeUnitElement (Lkotlinx/serialization/SerialDescriptor;I)V
public abstract fun endStructure (Lkotlinx/serialization/SerialDescriptor;)V
- public abstract fun getContext ()Lkotlinx/serialization/modules/SerialModule;
+ public abstract fun getSerializersModule ()Lkotlinx/serialization/modules/SerialModule;
public abstract fun shouldEncodeElementDefault (Lkotlinx/serialization/SerialDescriptor;I)Z
}
@@ -115,8 +115,7 @@ public abstract interface class kotlinx/serialization/Decoder {
public abstract fun decodeSerializableValue (Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public abstract fun decodeShort ()S
public abstract fun decodeString ()Ljava/lang/String;
- public abstract fun decodeUnit ()V
- public abstract fun getContext ()Lkotlinx/serialization/modules/SerialModule;
+ public abstract fun getSerializersModule ()Lkotlinx/serialization/modules/SerialModule;
public abstract fun getUpdateMode ()Lkotlinx/serialization/UpdateMode;
public abstract fun updateNullableSerializableValue (Lkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
public abstract fun updateSerializableValue (Lkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
@@ -133,7 +132,6 @@ public final class kotlinx/serialization/Decoder$DefaultImpls {
}
public final class kotlinx/serialization/DecodingKt {
- public static final fun decode (Lkotlinx/serialization/Decoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public static final fun decodeStructure (Lkotlinx/serialization/Decoder;Lkotlinx/serialization/SerialDescriptor;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
}
@@ -162,8 +160,7 @@ public abstract interface class kotlinx/serialization/Encoder {
public abstract fun encodeSerializableValue (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V
public abstract fun encodeShort (S)V
public abstract fun encodeString (Ljava/lang/String;)V
- public abstract fun encodeUnit ()V
- public abstract fun getContext ()Lkotlinx/serialization/modules/SerialModule;
+ public abstract fun getSerializersModule ()Lkotlinx/serialization/modules/SerialModule;
}
public final class kotlinx/serialization/Encoder$DefaultImpls {
@@ -177,7 +174,6 @@ public final class kotlinx/serialization/Encoder$DefaultImpls {
}
public final class kotlinx/serialization/EncodingKt {
- public static final fun encode (Lkotlinx/serialization/Encoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V
public static final fun encodeStructure (Lkotlinx/serialization/Encoder;Lkotlinx/serialization/SerialDescriptor;Lkotlin/jvm/functions/Function1;)V
}
@@ -202,10 +198,14 @@ public final class kotlinx/serialization/Mapper {
public final class kotlinx/serialization/MigrationsKt {
public static final fun compiledSerializer (Lkotlin/reflect/KClass;)Lkotlinx/serialization/KSerializer;
+ public static final fun decode (Lkotlinx/serialization/Decoder;)Ljava/lang/Object;
+ public static final fun decode (Lkotlinx/serialization/Decoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public static final fun dump (Lkotlinx/serialization/BinaryFormat;Ljava/lang/Object;)[B
public static final fun dump (Lkotlinx/serialization/BinaryFormat;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)[B
public static final fun dumps (Lkotlinx/serialization/BinaryFormat;Ljava/lang/Object;)Ljava/lang/String;
public static final fun dumps (Lkotlinx/serialization/BinaryFormat;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)Ljava/lang/String;
+ public static final fun encode (Lkotlinx/serialization/Encoder;Ljava/lang/Object;)V
+ public static final fun encode (Lkotlinx/serialization/Encoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V
public static final fun getContextualOrDefault (Lkotlinx/serialization/modules/SerialModule;Ljava/lang/Object;)Lkotlinx/serialization/KSerializer;
public static final fun getContextualOrDefault (Lkotlinx/serialization/modules/SerialModule;Lkotlin/reflect/KClass;)Lkotlinx/serialization/KSerializer;
public static final fun getList (Lkotlinx/serialization/KSerializer;)Lkotlinx/serialization/KSerializer;
@@ -554,11 +554,9 @@ public abstract class kotlinx/serialization/encoding/AbstractDecoder : kotlinx/s
public final fun decodeShortElement (Lkotlinx/serialization/SerialDescriptor;I)S
public fun decodeString ()Ljava/lang/String;
public final fun decodeStringElement (Lkotlinx/serialization/SerialDescriptor;I)Ljava/lang/String;
- public fun decodeUnit ()V
- public final fun decodeUnitElement (Lkotlinx/serialization/SerialDescriptor;I)V
public fun decodeValue ()Ljava/lang/Object;
public fun endStructure (Lkotlinx/serialization/SerialDescriptor;)V
- public fun getContext ()Lkotlinx/serialization/modules/SerialModule;
+ public fun getSerializersModule ()Lkotlinx/serialization/modules/SerialModule;
public fun getUpdateMode ()Lkotlinx/serialization/UpdateMode;
public fun updateNullableSerializableElement (Lkotlinx/serialization/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
public fun updateNullableSerializableValue (Lkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object;
@@ -599,10 +597,8 @@ public abstract class kotlinx/serialization/encoding/AbstractEncoder : kotlinx/s
public final fun encodeShortElement (Lkotlinx/serialization/SerialDescriptor;IS)V
public fun encodeString (Ljava/lang/String;)V
public final fun encodeStringElement (Lkotlinx/serialization/SerialDescriptor;ILjava/lang/String;)V
- public fun encodeUnit ()V
- public final fun encodeUnitElement (Lkotlinx/serialization/SerialDescriptor;I)V
public fun encodeValue (Ljava/lang/Object;)V
- public fun getContext ()Lkotlinx/serialization/modules/SerialModule;
+ public fun getSerializersModule ()Lkotlinx/serialization/modules/SerialModule;
public fun shouldEncodeElementDefault (Lkotlinx/serialization/SerialDescriptor;I)Z
}
@@ -1222,14 +1218,11 @@ public abstract class kotlinx/serialization/internal/TaggedDecoder : kotlinx/ser
protected fun decodeTaggedNull (Ljava/lang/Object;)Ljava/lang/Void;
protected fun decodeTaggedShort (Ljava/lang/Object;)S
protected fun decodeTaggedString (Ljava/lang/Object;)Ljava/lang/String;
- protected fun decodeTaggedUnit (Ljava/lang/Object;)V
protected fun decodeTaggedValue (Ljava/lang/Object;)Ljava/lang/Object;
- public final fun decodeUnit ()V
- public final fun decodeUnitElement (Lkotlinx/serialization/SerialDescriptor;I)V
public fun endStructure (Lkotlinx/serialization/SerialDescriptor;)V
- public fun getContext ()Lkotlinx/serialization/modules/SerialModule;
protected final fun getCurrentTag ()Ljava/lang/Object;
protected final fun getCurrentTagOrNull ()Ljava/lang/Object;
+ public fun getSerializersModule ()Lkotlinx/serialization/modules/SerialModule;
protected abstract fun getTag (Lkotlinx/serialization/SerialDescriptor;I)Ljava/lang/Object;
public fun getUpdateMode ()Lkotlinx/serialization/UpdateMode;
protected final fun popTag ()Ljava/lang/Object;
@@ -1284,15 +1277,12 @@ public abstract class kotlinx/serialization/internal/TaggedEncoder : kotlinx/ser
protected fun encodeTaggedNull (Ljava/lang/Object;)V
protected fun encodeTaggedShort (Ljava/lang/Object;S)V
protected fun encodeTaggedString (Ljava/lang/Object;Ljava/lang/String;)V
- protected fun encodeTaggedUnit (Ljava/lang/Object;)V
protected fun encodeTaggedValue (Ljava/lang/Object;Ljava/lang/Object;)V
- public final fun encodeUnit ()V
- public final fun encodeUnitElement (Lkotlinx/serialization/SerialDescriptor;I)V
protected fun endEncode (Lkotlinx/serialization/SerialDescriptor;)V
public final fun endStructure (Lkotlinx/serialization/SerialDescriptor;)V
- public fun getContext ()Lkotlinx/serialization/modules/SerialModule;
protected final fun getCurrentTag ()Ljava/lang/Object;
protected final fun getCurrentTagOrNull ()Ljava/lang/Object;
+ public fun getSerializersModule ()Lkotlinx/serialization/modules/SerialModule;
protected abstract fun getTag (Lkotlinx/serialization/SerialDescriptor;I)Ljava/lang/Object;
protected final fun popTag ()Ljava/lang/Object;
protected final fun pushTag (Ljava/lang/Object;)V
diff --git a/runtime/commonMain/src/kotlinx/serialization/ContextSerializer.kt b/runtime/commonMain/src/kotlinx/serialization/ContextSerializer.kt
index b8cd68dd..3a3df11c 100644
--- a/runtime/commonMain/src/kotlinx/serialization/ContextSerializer.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/ContextSerializer.kt
@@ -35,13 +35,13 @@ public class ContextSerializer<T : Any>(
public override fun serialize(encoder: Encoder, value: T) {
val clz = value::class
- val serializer = encoder.context.getContextual(clz) ?: fallbackSerializer ?: serializableClass.serializerNotRegistered()
+ val serializer = encoder.serializersModule.getContextual(clz) ?: fallbackSerializer ?: serializableClass.serializerNotRegistered()
@Suppress("UNCHECKED_CAST")
encoder.encodeSerializableValue(serializer as SerializationStrategy<T>, value)
}
public override fun deserialize(decoder: Decoder): T {
- val serializer = decoder.context.getContextual(serializableClass) ?: fallbackSerializer ?: serializableClass.serializerNotRegistered()
+ val serializer = decoder.serializersModule.getContextual(serializableClass) ?: fallbackSerializer ?: serializableClass.serializerNotRegistered()
return decoder.decodeSerializableValue(serializer)
}
}
diff --git a/runtime/commonMain/src/kotlinx/serialization/Decoding.kt b/runtime/commonMain/src/kotlinx/serialization/Decoding.kt
index a60582b5..03249ff4 100644
--- a/runtime/commonMain/src/kotlinx/serialization/Decoding.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/Decoding.kt
@@ -33,7 +33,7 @@ import kotlinx.serialization.modules.*
*
* If a class is represented as a structure or has multiple values in its serialized form,
* `decode*` methods are not that helpful, because format may not require a strict order of data
- * (e.g. JSON or XML), do not allow to work with collection types or establish structure boundaries.
+ * (e.g. JSON or XML), do not allow working with collection types or establish structure boundaries.
* All these capabilities are delegated to the [CompositeDecoder] interface with a more specific API surface.
* To denote a structure start, [beginStructure] should be used.
* ```
@@ -80,7 +80,7 @@ import kotlinx.serialization.modules.*
* JSON, for example, parses an opening bracket `{` during the `beginStructure` call, checks that the next key
* after this bracket is `stringValue` (using the descriptor), returns the value after the colon as string value
* and parses closing bracket `}` during the `endStructure`.
- * XML would do the roughly the same, but with different separators and parsing structures, while ProtoBuf
+ * XML would do roughly the same, but with different separators and parsing structures, while ProtoBuf
* machinery could be completely different.
* In any case, all these parsing details are encapsulated by a decoder.
*
@@ -103,7 +103,7 @@ public interface Decoder {
* Context of the current serialization process, including contextual and polymorphic serialization and,
* potentially, a format-specific configuration.
*/
- public val context: SerialModule
+ public val serializersModule: SerialModule
@Suppress("DEPRECATION")
@Deprecated(updateModeDeprecated, level = DeprecationLevel.ERROR)
@@ -131,9 +131,6 @@ public interface Decoder {
*/
public fun decodeNull(): Nothing?
- // Not documented, will be reworked
- public fun decodeUnit()
-
/**
* Decodes a boolean value.
* Corresponding kind is [PrimitiveKind.BOOLEAN].
@@ -278,31 +275,36 @@ public interface CompositeDecoder {
*/
public companion object {
/**
- * Value returned by [decodeElementIndex] when the underlying input has no more data
- * (apart from the end of the structure).
+ * Value returned by [decodeElementIndex] when the underlying input has no more data in the current structure.
* When this value is returned, no methods of the decoder should be called but [endStructure].
*/
+ public const val DECODE_DONE: Int = -1
+
+ /**
+ * Value returned by [decodeElementIndex] when the format encountered an unknown element
+ * (expected neither by the structure of serial descriptor, nor by the format itself).
+ */
+ public const val UNKNOWN_NAME: Int = -3
+
+ @Deprecated(
+ message = "READ_DONE was renamed to DECODE_DONE during 1.0 API stabilization",
+ level = DeprecationLevel.ERROR,
+ replaceWith = ReplaceWith("CompositeDecoder.DECODE_DONE")
+ )
public const val READ_DONE: Int = -1
@Deprecated(
message = "READ_ALL cannot be longer returned by 'decodeElementIndex', use 'decodeSequentially' instead",
level = DeprecationLevel.ERROR
)
- @Suppress("UNUSED")
public const val READ_ALL: Int = -2
-
- /**
- * Value returned by [decodeElementIndex] when the format encountered an unknown element
- * (expected neither by the structure of serial descriptor, nor by the format itself).
- */
- public const val UNKNOWN_NAME: Int = -3
}
/**
* Context of the current decoding process, including contextual and polymorphic serialization and,
* potentially, a format-specific configuration.
*/
- public val context: SerialModule
+ public val serializersModule: SerialModule
@Suppress("DEPRECATION")
@Deprecated(updateModeDeprecated, level = DeprecationLevel.ERROR)
@@ -361,7 +363,7 @@ public interface CompositeDecoder {
*
* If this method returns non-negative index, the caller should call one of the `decode*Element` methods
* with a resulting index.
- * Apart from positive values, this method can return [READ_DONE] to indicate that no more elements
+ * Apart from positive values, this method can return [DECODE_DONE] to indicate that no more elements
* are left or [UNKNOWN_NAME] to indicate that symbol with an unknown name was encountered.
*
* Example of usage:
@@ -377,7 +379,7 @@ public interface CompositeDecoder {
* var d: Double? = null
* while (true) {
* val index = composite.decodeElementIndex(descriptor)
- * if (index == READ_DONE) break // Input is over
+ * if (index == DECODE_DONE) break // Input is over
* when (index) {
* 0 -> {
* i = composite.decodeIntElement(descriptor, 0)
@@ -397,16 +399,16 @@ public interface CompositeDecoder {
* ```
* This example is a rough equivalent of what serialization plugin generates for serializable pair class.
*
- * The need in such loop comes from unstructured nature of most serialization formats.
+ * The need in such a loop comes from unstructured nature of most serialization formats.
* For example, JSON for the following input `{"d": 2.0, "i": 1}`, will first read `d` key with index `1`
- * and only after `i` with index `0`.
+ * and only after `i` with the index `0`.
*
* A potential implementation of this method for JSON format can be the following:
* ```
* fun decodeElementIndex(descriptor: SerialDescriptor): Int {
* // Ignore arrays
* val nextKey: String? = myStringJsonParser.nextKey()
- * if (nextKey == null) return READ_DONE
+ * if (nextKey == null) return DECODE_DONE
* return descriptor.getElementIndex(nextKey) // getElementIndex can return UNKNOWN_NAME
* }
* ```
@@ -421,9 +423,6 @@ public interface CompositeDecoder {
*/
public fun decodeCollectionSize(descriptor: SerialDescriptor): Int = -1
- // Not documented, was reworked
- public fun decodeUnitElement(descriptor: SerialDescriptor, index: Int)
-
/**
* Decodes a boolean value from the underlying input.
* The resulting value is associated with the [descriptor] element at the given [index].
@@ -570,17 +569,6 @@ public interface CompositeDecoder {
}
/**
- * Alias for [Decoder.decodeSerializableValue]
- */
-public fun <T : Any?> Decoder.decode(deserializer: DeserializationStrategy<T>): T =
- decodeSerializableValue(deserializer)
-
-/**
- * Reified version of [Decoder.decodeSerializableValue]
- */
-public inline fun <reified T : Any> Decoder.decode(): T = decode(serializer())
-
-/**
* Begins a structure, decodes it using the given [block], ends it and returns decoded element.
*/
public inline fun <T> Decoder.decodeStructure(
diff --git a/runtime/commonMain/src/kotlinx/serialization/Encoding.kt b/runtime/commonMain/src/kotlinx/serialization/Encoding.kt
index 0ad23025..fea5a7b0 100644
--- a/runtime/commonMain/src/kotlinx/serialization/Encoding.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/Encoding.kt
@@ -21,7 +21,7 @@ import kotlin.reflect.*
* To be more specific, serialization transforms a value into a sequence of "here is an int, here is
* a double, here a list of strings and here is another object that is a nested int", while encoding
* transforms this sequence into a format-specific commands such as "insert opening curly bracket
- * for a nested object start, insert a name of the value and the value separated with colon for an int etc."
+ * for a nested object start, insert a name of the value, and the value separated with colon for an int etc."
*
* The symmetric interface for the deserialization process is [Decoder].
*
@@ -30,10 +30,10 @@ import kotlin.reflect.*
* If a class is represented as a single [primitive][PrimitiveKind] value in its serialized form,
* then one of the `encode*` methods (e.g. [encodeInt]) can be used directly.
*
- * ### Serialization. Structured types
+ * ### Serialization. Structured types.
*
* If a class is represented as a structure or has multiple values in its serialized form,
- * `encode*` methods are not that helpful, because they do not allow to work with collection types or establish structure boundaries.
+ * `encode*` methods are not that helpful, because they do not allow working with collection types or establish structure boundaries.
* All these capabilities are delegated to the [CompositeEncoder] interface with a more specific API surface.
* To denote a structure start, [beginStructure] should be used.
* ```
@@ -77,11 +77,11 @@ import kotlin.reflect.*
* This serializer does not know anything about the underlying storage and will work with any properly-implemented encoder.
* JSON, for example, writes an opening bracket `{` during the `beginStructure` call, writes 'stringValue` key along
* with its value in `encodeStringElement` and writes the closing bracket `}` during the `endStructure`.
- * XML would do the roughly the same, but with different separators and structures, while ProtoBuf
+ * XML would do roughly the same, but with different separators and structures, while ProtoBuf
* machinery could be completely different.
* In any case, all these parsing details are encapsulated by an encoder.
*
- * ### Encoder implementation
+ * ### Encoder implementation.
*
* While being strictly typed, an underlying format can transform actual types in the way it wants.
* For example, a format can support only string types and encode/decode all primitives in a string form:
@@ -100,7 +100,7 @@ public interface Encoder {
* Context of the current serialization process, including contextual and polymorphic serialization and,
* potentially, a format-specific configuration.
*/
- public val context: SerialModule
+ public val serializersModule: SerialModule
/**
* Notifies the encoder that value of a nullable type that is
@@ -126,9 +126,6 @@ public interface Encoder {
*/
public fun encodeNull()
- // Not documented.
- public fun encodeUnit()
-
/**
* Encodes a boolean value.
* Corresponding kind is [PrimitiveKind.BOOLEAN].
@@ -226,7 +223,6 @@ public interface Encoder {
* composite.encodeStringElement(descriptor, 0, value.stringValue) // Serialize actual value
* composite.endStructure(descriptor) // Closing bracket
* }
- *
* ```
*/
@Suppress("DEPRECATION_ERROR", "RemoveRedundantSpreadOperator")
@@ -303,7 +299,7 @@ public interface CompositeEncoder {
* Context of the current serialization process, including contextual and polymorphic serialization and,
* potentially, a format-specific configuration.
*/
- public val context: SerialModule
+ public val serializersModule: SerialModule
/**
* Denotes the end of the structure associated with current encoder.
@@ -326,9 +322,6 @@ public interface CompositeEncoder {
*/
public fun shouldEncodeElementDefault(descriptor: SerialDescriptor, index: Int): Boolean = true
- // Not documented, was reworked
- public fun encodeUnitElement(descriptor: SerialDescriptor, index: Int)
-
/**
* Encodes a boolean [value] associated with an element at the given [index] in [serial descriptor][descriptor].
* The element at the given [index] should have [PrimitiveKind.BOOLEAN] kind.
@@ -415,17 +408,6 @@ public interface CompositeEncoder {
}
/**
- * Alias for [Encoder.encodeSerializableValue]
- */
-public fun <T : Any?> Encoder.encode(strategy: SerializationStrategy<T>, value: T): Unit =
- encodeSerializableValue(strategy, value)
-
-/**
- * Reified version of [Encoder.encodeSerializableValue]
- */
-public inline fun <reified T : Any> Encoder.encode(obj: T): Unit = encode(serializer(), obj)
-
-/**
* Begins a structure, encodes it using the given [block] and ends it.
*/
public inline fun Encoder.encodeStructure(descriptor: SerialDescriptor, crossinline block: CompositeEncoder.() -> Unit) {
diff --git a/runtime/commonMain/src/kotlinx/serialization/KSerializer.kt b/runtime/commonMain/src/kotlinx/serialization/KSerializer.kt
index e36c0eae..fefd1386 100644
--- a/runtime/commonMain/src/kotlinx/serialization/KSerializer.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/KSerializer.kt
@@ -153,7 +153,7 @@ public interface DeserializationStrategy<T> {
* var list: List<String>? = null
* loop@ while (true) {
* when (val index = decodeElementIndex(descriptor)) {
- * READ_DONE -> break@loop
+ * DECODE_DONE -> break@loop
* 0 -> {
* // Decode 'int' property as Int
* int = decodeIntElement(descriptor, index = 0)
diff --git a/runtime/commonMain/src/kotlinx/serialization/Migrations.kt b/runtime/commonMain/src/kotlinx/serialization/Migrations.kt
index 65f54cff..54b8a822 100644
--- a/runtime/commonMain/src/kotlinx/serialization/Migrations.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/Migrations.kt
@@ -246,3 +246,27 @@ public fun <T : Any> BinaryFormat.load(raw: ByteArray): T = noImpl()
ReplaceWith("decodeFromHexString<T>(hex)"), DeprecationLevel.ERROR
)
public fun <T : Any> BinaryFormat.loads(hex: String): T = noImpl()
+
+@Deprecated(
+ "This method was deprecated during serialization 1.0 API stabilization",
+ ReplaceWith("decodeSerializableValue(deserializer)"), DeprecationLevel.ERROR
+) // TODO make internal when migrations are removed
+public fun <T : Any?> Decoder.decode(deserializer: DeserializationStrategy<T>): T = noImpl()
+
+@Deprecated(
+ "This method was deprecated during serialization 1.0 API stabilization",
+ ReplaceWith("decodeSerializableValue<T>(serializer())"), DeprecationLevel.ERROR
+) // TODO make internal when migrations are removed
+public fun <T : Any> Decoder.decode(): T = noImpl()
+
+@Deprecated(
+ "This method was deprecated during serialization 1.0 API stabilization",
+ ReplaceWith("encodeSerializableValue(strategy, value)"), DeprecationLevel.ERROR
+) // TODO make internal when migrations are removed
+public fun <T : Any?> Encoder.encode(strategy: SerializationStrategy<T>, value: T): Unit = noImpl()
+
+@Deprecated(
+ "This method was deprecated during serialization 1.0 API stabilization",
+ ReplaceWith("encodeSerializableValue<T>(serializer(), value)"), DeprecationLevel.ERROR
+) // TODO make internal when migrations are removed
+public fun <T : Any> Encoder.encode(obj: T): Unit = noImpl()
diff --git a/runtime/commonMain/src/kotlinx/serialization/encoding/AbstractDecoder.kt b/runtime/commonMain/src/kotlinx/serialization/encoding/AbstractDecoder.kt
index 5dd6ddb5..a174858f 100644
--- a/runtime/commonMain/src/kotlinx/serialization/encoding/AbstractDecoder.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/encoding/AbstractDecoder.kt
@@ -15,7 +15,7 @@ import kotlinx.serialization.modules.*
* See [Decoder] documentation for information about each particular `decode*` method.
*/
public abstract class AbstractDecoder : Decoder, CompositeDecoder {
- override val context: SerialModule
+ override val serializersModule: SerialModule
get() = EmptyModule
@Suppress("DEPRECATION")
@@ -29,8 +29,6 @@ public abstract class AbstractDecoder : Decoder, CompositeDecoder {
override fun decodeNotNullMark(): Boolean = true
override fun decodeNull(): Nothing? = null
- override fun decodeUnit(): Unit = Unit.serializer().deserialize(this)
-
override fun decodeBoolean(): Boolean = decodeValue() as Boolean
override fun decodeByte(): Byte = decodeValue() as Byte
override fun decodeShort(): Short = decodeValue() as Short
@@ -63,7 +61,6 @@ public abstract class AbstractDecoder : Decoder, CompositeDecoder {
override fun endStructure(descriptor: SerialDescriptor) {
}
- final override fun decodeUnitElement(descriptor: SerialDescriptor, index: Int): Unit = decodeUnit()
final override fun decodeBooleanElement(descriptor: SerialDescriptor, index: Int): Boolean = decodeBoolean()
final override fun decodeByteElement(descriptor: SerialDescriptor, index: Int): Byte = decodeByte()
final override fun decodeShortElement(descriptor: SerialDescriptor, index: Int): Short = decodeShort()
diff --git a/runtime/commonMain/src/kotlinx/serialization/encoding/AbstractEncoder.kt b/runtime/commonMain/src/kotlinx/serialization/encoding/AbstractEncoder.kt
index 1fe836f2..27bf294c 100644
--- a/runtime/commonMain/src/kotlinx/serialization/encoding/AbstractEncoder.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/encoding/AbstractEncoder.kt
@@ -15,7 +15,7 @@ import kotlinx.serialization.modules.*
* See [Encoder] documentation for information about each particular `encode*` method.
*/
public abstract class AbstractEncoder : Encoder, CompositeEncoder {
- override val context: SerialModule
+ override val serializersModule: SerialModule
get() = EmptyModule
// do not update signature here because new signature is called by the plugin;
@@ -49,10 +49,6 @@ public abstract class AbstractEncoder : Encoder, CompositeEncoder {
throw SerializationException("'null' is not supported by default")
}
- override fun encodeUnit() {
- Unit.serializer().serialize(this, Unit)
- }
-
override fun encodeBoolean(value: Boolean): Unit = encodeValue(value)
override fun encodeByte(value: Byte): Unit = encodeValue(value)
override fun encodeShort(value: Short): Unit = encodeValue(value)
@@ -65,7 +61,6 @@ public abstract class AbstractEncoder : Encoder, CompositeEncoder {
override fun encodeEnum(enumDescriptor: SerialDescriptor, index: Int): Unit = encodeValue(index)
// Delegating implementation of CompositeEncoder
- final override fun encodeUnitElement(descriptor: SerialDescriptor, index: Int) { if (encodeElement(descriptor, index)) encodeUnit() }
final override fun encodeBooleanElement(descriptor: SerialDescriptor, index: Int, value: Boolean) { if (encodeElement(descriptor, index)) encodeBoolean(value) }
final override fun encodeByteElement(descriptor: SerialDescriptor, index: Int, value: Byte) { if (encodeElement(descriptor, index)) encodeByte(value) }
final override fun encodeShortElement(descriptor: SerialDescriptor, index: Int, value: Short) { if (encodeElement(descriptor, index)) encodeShort(value) }
diff --git a/runtime/commonMain/src/kotlinx/serialization/internal/AbstractPolymorphicSerializer.kt b/runtime/commonMain/src/kotlinx/serialization/internal/AbstractPolymorphicSerializer.kt
index 4bc9b114..1e5f5e07 100644
--- a/runtime/commonMain/src/kotlinx/serialization/internal/AbstractPolymorphicSerializer.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/internal/AbstractPolymorphicSerializer.kt
@@ -42,7 +42,7 @@ public abstract class AbstractPolymorphicSerializer<T : Any> internal constructo
mainLoop@ while (true) {
when (val index = decodeElementIndex(descriptor)) {
- CompositeDecoder.READ_DONE -> {
+ CompositeDecoder.DECODE_DONE -> {
break@mainLoop
}
0 -> {
@@ -56,7 +56,7 @@ public abstract class AbstractPolymorphicSerializer<T : Any> internal constructo
else -> throw SerializationException(
"Invalid index in polymorphic deserialization of " +
(klassName ?: "unknown class") +
- "\n Expected 0, 1 or READ_DONE(-1), but found $index"
+ "\n Expected 0, 1 or DECODE_DONE(-1), but found $index"
)
}
}
@@ -80,7 +80,7 @@ public abstract class AbstractPolymorphicSerializer<T : Any> internal constructo
public open fun findPolymorphicSerializer(
decoder: CompositeDecoder,
klassName: String
- ): DeserializationStrategy<out T> = decoder.context.getPolymorphic(baseClass, klassName)
+ ): DeserializationStrategy<out T> = decoder.serializersModule.getPolymorphic(baseClass, klassName)
?: throwSubtypeNotRegistered(klassName, baseClass)
@@ -93,7 +93,7 @@ public abstract class AbstractPolymorphicSerializer<T : Any> internal constructo
encoder: Encoder,
value: T
): SerializationStrategy<T> =
- encoder.context.getPolymorphic(baseClass, value) ?: throwSubtypeNotRegistered(value::class, baseClass)
+ encoder.serializersModule.getPolymorphic(baseClass, value) ?: throwSubtypeNotRegistered(value::class, baseClass)
}
private fun throwSubtypeNotRegistered(subClassName: String, baseClass: KClass<*>): Nothing =
diff --git a/runtime/commonMain/src/kotlinx/serialization/internal/CollectionSerializers.kt b/runtime/commonMain/src/kotlinx/serialization/internal/CollectionSerializers.kt
index acde6b0e..66b7df41 100644
--- a/runtime/commonMain/src/kotlinx/serialization/internal/CollectionSerializers.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/internal/CollectionSerializers.kt
@@ -5,7 +5,6 @@
package kotlinx.serialization.internal
import kotlinx.serialization.*
-import kotlinx.serialization.CompositeDecoder.Companion.READ_DONE
import kotlin.reflect.*
@InternalSerializationApi
@@ -30,7 +29,7 @@ public sealed class AbstractCollectionSerializer<Element, Collection, Builder> :
} else {
while (true) {
val index = compositeDecoder.decodeElementIndex(descriptor)
- if (index == READ_DONE) break
+ if (index == CompositeDecoder.DECODE_DONE) break
readElement(compositeDecoder, startIndex + index, builder)
}
}
diff --git a/runtime/commonMain/src/kotlinx/serialization/internal/Tagged.kt b/runtime/commonMain/src/kotlinx/serialization/internal/Tagged.kt
index 2a6c39c5..933cddc8 100644
--- a/runtime/commonMain/src/kotlinx/serialization/internal/Tagged.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/internal/Tagged.kt
@@ -6,11 +6,6 @@ package kotlinx.serialization.internal
import kotlinx.serialization.*
import kotlinx.serialization.modules.*
-
-internal const val unitDeprecated =
- "This method is deprecated with no replacement. Unit is encoded as an empty object and does not require a dedicated method. " +
- "To migrate, just remove your own implementation of this method"
-
/*
* These classes are intended to be used only within the kotlinx.serialization.
* They neither do have stable API, not internal invariants and are changed without any warnings.
@@ -24,7 +19,7 @@ public abstract class TaggedEncoder<Tag : Any?> : Encoder, CompositeEncoder {
*/
protected abstract fun SerialDescriptor.getTag(index: Int): Tag
- override val context: SerialModule
+ override val serializersModule: SerialModule
get() = EmptyModule
// ---- API ----
@@ -34,8 +29,6 @@ public abstract class TaggedEncoder<Tag : Any?> : Encoder, CompositeEncoder {
protected open fun encodeTaggedNotNullMark(tag: Tag) {}
protected open fun encodeTaggedNull(tag: Tag): Unit = throw SerializationException("null is not supported")
- @Deprecated(message = unitDeprecated, level = DeprecationLevel.ERROR)
- protected open fun encodeTaggedUnit(tag: Tag): Unit = encodeTaggedValue(tag, Unit)
protected open fun encodeTaggedInt(tag: Tag, value: Int): Unit = encodeTaggedValue(tag, value)
protected open fun encodeTaggedByte(tag: Tag, value: Byte): Unit = encodeTaggedValue(tag, value)
protected open fun encodeTaggedShort(tag: Tag, value: Short): Unit = encodeTaggedValue(tag, value)
@@ -62,9 +55,6 @@ public abstract class TaggedEncoder<Tag : Any?> : Encoder, CompositeEncoder {
final override fun encodeNotNullMark(): Unit = encodeTaggedNotNullMark(currentTag)
final override fun encodeNull(): Unit = encodeTaggedNull(popTag())
-
- @Suppress("DEPRECATION_ERROR")
- final override fun encodeUnit(): Unit = UnitSerializer.serialize(this, Unit)
final override fun encodeBoolean(value: Boolean): Unit = encodeTaggedBoolean(popTag(), value)
final override fun encodeByte(value: Byte): Unit = encodeTaggedByte(popTag(), value)
final override fun encodeShort(value: Short): Unit = encodeTaggedShort(popTag(), value)
@@ -107,10 +97,6 @@ public abstract class TaggedEncoder<Tag : Any?> : Encoder, CompositeEncoder {
*/
protected open fun endEncode(descriptor: SerialDescriptor) {}
- @Suppress("DEPRECATION_ERROR")
- final override fun encodeUnitElement(descriptor: SerialDescriptor, index: Int): Unit =
- encodeTaggedUnit(descriptor.getTag(index))
-
final override fun encodeBooleanElement(descriptor: SerialDescriptor, index: Int, value: Boolean): Unit =
encodeTaggedBoolean(descriptor.getTag(index), value)
@@ -187,7 +173,7 @@ public abstract class NamedValueEncoder(protected val rootName: String = "") : T
@InternalSerializationApi
public abstract class TaggedDecoder<Tag : Any?> : Decoder,
CompositeDecoder {
- override val context: SerialModule
+ override val serializersModule: SerialModule
get() = EmptyModule
@Suppress("DEPRECATION")
@@ -205,9 +191,6 @@ public abstract class TaggedDecoder<Tag : Any?> : Decoder,
protected open fun decodeTaggedNotNullMark(tag: Tag): Boolean = true
protected open fun decodeTaggedNull(tag: Tag): Nothing? = null
- @Deprecated(message = unitDeprecated, level = DeprecationLevel.ERROR)
- @Suppress("DEPRECATION_ERROR")
- protected open fun decodeTaggedUnit(tag: Tag): Unit = UnitSerializer.deserialize(this)
protected open fun decodeTaggedBoolean(tag: Tag): Boolean = decodeTaggedValue(tag) as Boolean
protected open fun decodeTaggedByte(tag: Tag): Byte = decodeTaggedValue(tag) as Byte
protected open fun decodeTaggedShort(tag: Tag): Short = decodeTaggedValue(tag) as Short
@@ -229,9 +212,6 @@ public abstract class TaggedDecoder<Tag : Any?> : Decoder,
final override fun decodeNotNullMark(): Boolean = decodeTaggedNotNullMark(currentTag)
final override fun decodeNull(): Nothing? = null
- @Deprecated(message = unitDeprecated, level = DeprecationLevel.ERROR)
- @Suppress("DEPRECATION_ERROR")
- final override fun decodeUnit(): Unit = UnitSerializer.deserialize(this)
final override fun decodeBoolean(): Boolean = decodeTaggedBoolean(popTag())
final override fun decodeByte(): Byte = decodeTaggedByte(popTag())
final override fun decodeShort(): Short = decodeTaggedShort(popTag())
@@ -260,11 +240,6 @@ public abstract class TaggedDecoder<Tag : Any?> : Decoder,
// Nothing
}
- @Deprecated(message = unitDeprecated, level = DeprecationLevel.ERROR)
- @Suppress("DEPRECATION_ERROR")
- final override fun decodeUnitElement(descriptor: SerialDescriptor, index: Int): Unit =
- decodeTaggedUnit(descriptor.getTag(index))
-
final override fun decodeBooleanElement(descriptor: SerialDescriptor, index: Int): Boolean =
decodeTaggedBoolean(descriptor.getTag(index))
diff --git a/runtime/commonMain/src/kotlinx/serialization/internal/Tuples.kt b/runtime/commonMain/src/kotlinx/serialization/internal/Tuples.kt
index 5c3ee0dc..862ec3d4 100644
--- a/runtime/commonMain/src/kotlinx/serialization/internal/Tuples.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/internal/Tuples.kt
@@ -43,7 +43,7 @@ public sealed class KeyValueSerializer<K, V, R>(
var value: Any? = NULL
mainLoop@ while (true) {
when (val idx = composite.decodeElementIndex(descriptor)) {
- CompositeDecoder.READ_DONE -> {
+ CompositeDecoder.DECODE_DONE -> {
break@mainLoop
}
0 -> {
@@ -163,7 +163,7 @@ public class TripleSerializer<A, B, C>(
var c: Any? = NULL
mainLoop@ while (true) {
when (val index = composite.decodeElementIndex(descriptor)) {
- CompositeDecoder.READ_DONE -> {
+ CompositeDecoder.DECODE_DONE -> {
break@mainLoop
}
0 -> {
diff --git a/runtime/commonMain/src/kotlinx/serialization/json/Json.kt b/runtime/commonMain/src/kotlinx/serialization/json/Json.kt
index ae028d98..6acf6d3c 100644
--- a/runtime/commonMain/src/kotlinx/serialization/json/Json.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/json/Json.kt
@@ -61,7 +61,7 @@ public sealed class Json(internal val configuration: JsonConfiguration) : String
WriteMode.OBJ,
arrayOfNulls(WriteMode.values().size)
)
- encoder.encode(serializer, value)
+ encoder.encodeSerializableValue(serializer, value)
return result.toString()
}
@@ -73,7 +73,7 @@ public sealed class Json(internal val configuration: JsonConfiguration) : String
public final override fun <T> decodeFromString(deserializer: DeserializationStrategy<T>, string: String): T {
val reader = JsonReader(string)
val input = StreamingJsonDecoder(this, WriteMode.OBJ, reader)
- val result = input.decode(deserializer)
+ val result = input.decodeSerializableValue(deserializer)
if (!reader.isDone) { error("Reader has not consumed the whole input: $reader") }
return result
}
diff --git a/runtime/commonMain/src/kotlinx/serialization/json/JsonParametricSerializer.kt b/runtime/commonMain/src/kotlinx/serialization/json/JsonParametricSerializer.kt
index 960a84e7..739f20c9 100644
--- a/runtime/commonMain/src/kotlinx/serialization/json/JsonParametricSerializer.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/json/JsonParametricSerializer.kt
@@ -76,7 +76,7 @@ public abstract class JsonParametricSerializer<T : Any>(private val baseClass: K
@OptIn(UnsafeSerializationApi::class)
final override fun serialize(encoder: Encoder, value: T) {
val actualSerializer =
- encoder.context.getPolymorphic(baseClass, value)
+ encoder.serializersModule.getPolymorphic(baseClass, value)
?: value::class.serializerOrNull()
?: throwSubtypeNotRegistered(value::class, baseClass)
@Suppress("UNCHECKED_CAST")
diff --git a/runtime/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt b/runtime/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt
index 57696c53..c49d5b89 100644
--- a/runtime/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt
@@ -20,7 +20,7 @@ internal class StreamingJsonDecoder internal constructor(
@JvmField internal val reader: JsonReader
) : JsonDecoder, AbstractDecoder() {
- public override val context: SerialModule = json.context
+ public override val serializersModule: SerialModule = json.context
private var currentIndex = -1
private val configuration = json.configuration
@@ -85,7 +85,7 @@ internal class StreamingJsonDecoder internal constructor(
0 -> 0
1 -> 1
else -> {
- CompositeDecoder.READ_DONE
+ CompositeDecoder.DECODE_DONE
}
}
}
@@ -103,7 +103,7 @@ internal class StreamingJsonDecoder internal constructor(
}
return if (!reader.canBeginValue) {
reader.require(tokenClass != TC_COMMA) { "Unexpected trailing comma" }
- CompositeDecoder.READ_DONE
+ CompositeDecoder.DECODE_DONE
} else {
++currentIndex
}
@@ -159,7 +159,7 @@ internal class StreamingJsonDecoder internal constructor(
reader.require(reader.canBeginValue, reader.currentPosition) { "Unexpected trailing comma" }
}
}
- return CompositeDecoder.READ_DONE
+ return CompositeDecoder.DECODE_DONE
}
private fun decodeListIndex(tokenClass: Byte): Int {
@@ -169,7 +169,7 @@ internal class StreamingJsonDecoder internal constructor(
}
return if (!reader.canBeginValue) {
reader.require(tokenClass != TC_COMMA) { "Unexpected trailing comma" }
- CompositeDecoder.READ_DONE
+ CompositeDecoder.DECODE_DONE
} else {
++currentIndex
}
diff --git a/runtime/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt b/runtime/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt
index 6b03c028..2181f969 100644
--- a/runtime/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt
@@ -22,7 +22,7 @@ internal class StreamingJsonEncoder(
modeReuseCache: Array<JsonEncoder?>
) : this(Composer(output, json), json, mode, modeReuseCache)
- public override val context: SerialModule = json.context
+ public override val serializersModule: SerialModule = json.context
private val configuration = json.configuration
// Forces serializer to wrap all values into quotes
diff --git a/runtime/commonMain/src/kotlinx/serialization/json/internal/TreeJsonInput.kt b/runtime/commonMain/src/kotlinx/serialization/json/internal/TreeJsonInput.kt
index 36b1dbd1..4f9a77cf 100644
--- a/runtime/commonMain/src/kotlinx/serialization/json/internal/TreeJsonInput.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/json/internal/TreeJsonInput.kt
@@ -18,7 +18,7 @@ internal fun <T> Json.readJson(element: JsonElement, deserializer: Deserializati
is JsonArray -> JsonTreeListDecoder(this, element)
is JsonLiteral, JsonNull -> JsonPrimitiveDecoder(this, element as JsonPrimitive)
}
- return input.decode(deserializer)
+ return input.decodeSerializableValue(deserializer)
}
internal fun <T> Json.readPolymorphicJson(
@@ -26,7 +26,7 @@ internal fun <T> Json.readPolymorphicJson(
element: JsonObject,
deserializer: DeserializationStrategy<T>
): T {
- return JsonTreeDecoder(this, element, discriminator, deserializer.descriptor).decode(deserializer)
+ return JsonTreeDecoder(this, element, discriminator, deserializer.descriptor).decodeSerializableValue(deserializer)
}
private sealed class AbstractJsonTreeDecoder(
@@ -34,7 +34,7 @@ private sealed class AbstractJsonTreeDecoder(
open val value: JsonElement
) : NamedValueDecoder(), JsonDecoder {
- override val context: SerialModule
+ override val serializersModule: SerialModule
get() = json.context
// must override public final val updateMode: UpdateMode defined in kotlinx.serialization.NamedValueDecoder
@@ -91,10 +91,6 @@ private sealed class AbstractJsonTreeDecoder(
override fun decodeTaggedNotNullMark(tag: String): Boolean = currentElement(tag) !== JsonNull
- override fun decodeTaggedUnit(tag: String) {
- return
- }
-
override fun decodeTaggedBoolean(tag: String): Boolean {
val value = getValue(tag)
if (!json.configuration.isLenient) {
@@ -178,7 +174,7 @@ private open class JsonTreeDecoder(
return position - 1
}
}
- return CompositeDecoder.READ_DONE
+ return CompositeDecoder.DECODE_DONE
}
override fun currentElement(tag: String): JsonElement = value.getValue(tag)
@@ -219,7 +215,7 @@ private class JsonTreeMapDecoder(json: Json, override val value: JsonObject) : J
position++
return position
}
- return CompositeDecoder.READ_DONE
+ return CompositeDecoder.DECODE_DONE
}
override fun currentElement(tag: String): JsonElement {
@@ -246,6 +242,6 @@ private class JsonTreeListDecoder(json: Json, override val value: JsonArray) : A
currentIndex++
return currentIndex
}
- return CompositeDecoder.READ_DONE
+ return CompositeDecoder.DECODE_DONE
}
}
diff --git a/runtime/commonMain/src/kotlinx/serialization/json/internal/TreeJsonOutput.kt b/runtime/commonMain/src/kotlinx/serialization/json/internal/TreeJsonOutput.kt
index d736addd..75dcc1ea 100644
--- a/runtime/commonMain/src/kotlinx/serialization/json/internal/TreeJsonOutput.kt
+++ b/runtime/commonMain/src/kotlinx/serialization/json/internal/TreeJsonOutput.kt
@@ -14,7 +14,7 @@ import kotlin.jvm.*
internal fun <T> Json.writeJson(value: T, serializer: SerializationStrategy<T>): JsonElement {
lateinit var result: JsonElement
val encoder = JsonTreeEncoder(this) { result = it }
- encoder.encode(serializer, value)
+ encoder.encodeSerializableValue(serializer, value)
return result
}
@@ -23,7 +23,7 @@ private sealed class AbstractJsonTreeEncoder(
val nodeConsumer: (JsonElement) -> Unit
) : NamedValueEncoder(), JsonEncoder {
- final override val context: SerialModule
+ final override val serializersModule: SerialModule
get() = json.context
@JvmField
diff --git a/runtime/commonTest/src/kotlinx/serialization/BasicTypesSerializationTest.kt b/runtime/commonTest/src/kotlinx/serialization/BasicTypesSerializationTest.kt
index 9cbf0a01..7a0ec5d4 100644
--- a/runtime/commonTest/src/kotlinx/serialization/BasicTypesSerializationTest.kt
+++ b/runtime/commonTest/src/kotlinx/serialization/BasicTypesSerializationTest.kt
@@ -4,7 +4,6 @@
package kotlinx.serialization
-import kotlinx.serialization.CompositeDecoder.Companion.READ_DONE
import kotlinx.serialization.encoding.*
import kotlin.test.*
@@ -62,7 +61,7 @@ class BasicTypesSerializationTest {
inp.skipWhitespace(',')
val name = inp.nextUntil(':', '}')
if (name.isEmpty())
- return READ_DONE
+ return CompositeDecoder.DECODE_DONE
val index = descriptor.getElementIndexOrThrow(name)
inp.expect(':')
return index
@@ -153,11 +152,11 @@ class BasicTypesSerializationTest {
// serialize to string
val sb = StringBuilder()
val out = KeyValueOutput(sb)
- out.encode(TypesUmbrella.serializer(), umbrellaInstance)
+ out.encodeSerializableValue(TypesUmbrella.serializer(), umbrellaInstance)
// deserialize from string
val str = sb.toString()
val inp = KeyValueInput(Parser(StringReader(str)))
- val other = inp.decode(TypesUmbrella.serializer())
+ val other = inp.decodeSerializableValue(TypesUmbrella.serializer())
// assert we've got it back from string
assertEquals(umbrellaInstance, other)
assertNotSame(umbrellaInstance, other)
diff --git a/runtime/commonTest/src/kotlinx/serialization/TaggedTest.kt b/runtime/commonTest/src/kotlinx/serialization/TaggedTest.kt
index 492be4f9..0c472353 100644
--- a/runtime/commonTest/src/kotlinx/serialization/TaggedTest.kt
+++ b/runtime/commonTest/src/kotlinx/serialization/TaggedTest.kt
@@ -4,7 +4,6 @@
package kotlinx.serialization
-import kotlinx.serialization.CompositeDecoder.Companion.READ_DONE
import kotlinx.serialization.test.*
import kotlin.test.*
import kotlinx.serialization.internal.*
@@ -36,7 +35,7 @@ class TaggedTest {
override fun decodeElementIndex(descriptor: SerialDescriptor): Int {
// js doesn't generate code for .decodeSequentially for the sake of keeping output small
if (!isJs()) throw AssertionError("Should not be called in this test due to support of decodeSequentially")
- return if (i == collected.tagList.size) READ_DONE else i++
+ return if (i == collected.tagList.size) CompositeDecoder.DECODE_DONE else i++
}
override fun decodeTaggedValue(tag: Int?): Any {
@@ -49,9 +48,9 @@ class TaggedTest {
fun testTagged() {
val collector = Collector()
val data = DataWithId(1, "2")
- collector.encode(DataWithId.serializer(), data)
+ collector.encodeSerializableValue(DataWithId.serializer(), data)
assertEquals(mapOf(1 to 1, 2 to "2", null to Unit, 42 to true), collector.tagList, "see all tags properly")
- val obj = Emitter(collector).decode(DataWithId.serializer())
+ val obj = Emitter(collector).decodeSerializableValue(DataWithId.serializer())
assertEquals(obj, data, "read tags back")
}
}
diff --git a/runtime/commonTest/src/kotlinx/serialization/UnknownElementIndexTest.kt b/runtime/commonTest/src/kotlinx/serialization/UnknownElementIndexTest.kt
index 25da54e0..74196116 100644
--- a/runtime/commonTest/src/kotlinx/serialization/UnknownElementIndexTest.kt
+++ b/runtime/commonTest/src/kotlinx/serialization/UnknownElementIndexTest.kt
@@ -25,7 +25,7 @@ class UnknownElementIndexTest {
@Test
fun testCompilerComplainsAboutIncorrectIndex() {
assertFailsWith(UnknownFieldException::class) {
- MalformedReader().decode(Holder.serializer())
+ MalformedReader().decodeSerializableValue(Holder.serializer())
}
}
diff --git a/runtime/commonTest/src/kotlinx/serialization/features/BinaryPayloadExampleTest.kt b/runtime/commonTest/src/kotlinx/serialization/features/BinaryPayloadExampleTest.kt
index 96060d43..e1605d26 100644
--- a/runtime/commonTest/src/kotlinx/serialization/features/BinaryPayloadExampleTest.kt
+++ b/runtime/commonTest/src/kotlinx/serialization/features/BinaryPayloadExampleTest.kt
@@ -34,7 +34,7 @@ class BinaryPayloadExampleTest {
var res: ByteArray? = null // need to read nullable non-optional properties
loop@ while (true) {
when (val i = dec.decodeElementIndex(descriptor)) {
- CompositeDecoder.READ_DONE -> break@loop
+ CompositeDecoder.DECODE_DONE -> break@loop
0 -> req = InternalHexConverter.parseHexBinary(dec.decodeStringElement(descriptor, i))
1 -> res = InternalHexConverter.parseHexBinary(dec.decodeStringElement(descriptor, i))
else -> throw SerializationException("Unknown index $i")
diff --git a/runtime/commonTest/src/kotlinx/serialization/features/GenericCustomSerializerTest.kt b/runtime/commonTest/src/kotlinx/serialization/features/GenericCustomSerializerTest.kt
index 2520965e..f19ff5dd 100644
--- a/runtime/commonTest/src/kotlinx/serialization/features/GenericCustomSerializerTest.kt
+++ b/runtime/commonTest/src/kotlinx/serialization/features/GenericCustomSerializerTest.kt
@@ -51,7 +51,7 @@ class CheckedDataSerializer<T : Any>(private val dataSerializer: KSerializer<T>)
lateinit var sum: ByteArray
loop@ while (true) {
when (val i = inp.decodeElementIndex(descriptor)) {
- CompositeDecoder.READ_DONE -> break@loop
+ CompositeDecoder.DECODE_DONE -> break@loop
0 -> data = inp.decodeSerializableElement(descriptor, i, dataSerializer)
1 -> sum = InternalHexConverter.parseHexBinary(inp.decodeStringElement(descriptor, i))
else -> throw SerializationException("Unknown index $i")
diff --git a/runtime/commonTest/src/kotlinx/serialization/json/MapLikeSerializerTest.kt b/runtime/commonTest/src/kotlinx/serialization/json/MapLikeSerializerTest.kt
index f58a74a8..5594ce04 100644
--- a/runtime/commonTest/src/kotlinx/serialization/json/MapLikeSerializerTest.kt
+++ b/runtime/commonTest/src/kotlinx/serialization/json/MapLikeSerializerTest.kt
@@ -40,7 +40,7 @@ class MapLikeSerializerTest : JsonTestBase() {
var value: String? = null
mainLoop@ while (true) {
when (val idx = composite.decodeElementIndex(descriptor)) {
- CompositeDecoder.READ_DONE -> {
+ CompositeDecoder.DECODE_DONE -> {
break@mainLoop
}
0 -> {
diff --git a/runtime/jsMain/src/kotlinx/serialization/DynamicObjectParser.kt b/runtime/jsMain/src/kotlinx/serialization/DynamicObjectParser.kt
index 35118051..51d596f4 100644
--- a/runtime/jsMain/src/kotlinx/serialization/DynamicObjectParser.kt
+++ b/runtime/jsMain/src/kotlinx/serialization/DynamicObjectParser.kt
@@ -4,7 +4,6 @@
package kotlinx.serialization
-import kotlinx.serialization.CompositeDecoder.Companion.READ_DONE
import kotlinx.serialization.internal.*
import kotlinx.serialization.json.*
import kotlinx.serialization.modules.*
@@ -52,10 +51,10 @@ public class DynamicObjectParser @OptIn(UnstableDefault::class) constructor(
* Deserializes given [obj] from dynamic form to type [T] using [deserializer].
*/
public fun <T> parse(obj: dynamic, deserializer: DeserializationStrategy<T>): T =
- DynamicInput(obj).decode(deserializer)
+ DynamicInput(obj).decodeSerializableValue(deserializer)
private open inner class DynamicInput(val obj: dynamic) : NamedValueDecoder() {
- override val context: SerialModule
+ override val serializersModule: SerialModule
get() = this@DynamicObjectParser.context
override fun composeName(parentName: String, childName: String): String = childName
@@ -67,7 +66,7 @@ public class DynamicObjectParser @OptIn(UnstableDefault::class) constructor(
val name = descriptor.getTag(pos++)
if (obj[name] !== undefined) return pos - 1
}
- return READ_DONE
+ return CompositeDecoder.DECODE_DONE
}
override fun decodeTaggedEnum(tag: String, enumDescription: SerialDescriptor): Int =
@@ -141,7 +140,7 @@ public class DynamicObjectParser @OptIn(UnstableDefault::class) constructor(
val name = keys[i] as String
if (this.obj[name] !== undefined) return pos
}
- return READ_DONE
+ return CompositeDecoder.DECODE_DONE
}
override fun getByTag(tag: String): dynamic {
@@ -160,7 +159,7 @@ public class DynamicObjectParser @OptIn(UnstableDefault::class) constructor(
val o = obj[++pos]
if (o !== undefined) return pos
}
- return READ_DONE
+ return CompositeDecoder.DECODE_DONE
}
}
}
diff --git a/runtime/jsMain/src/kotlinx/serialization/DynamicObjectSerializer.kt b/runtime/jsMain/src/kotlinx/serialization/DynamicObjectSerializer.kt
index 675b8393..8bef5f9c 100644
--- a/runtime/jsMain/src/kotlinx/serialization/DynamicObjectSerializer.kt
+++ b/runtime/jsMain/src/kotlinx/serialization/DynamicObjectSerializer.kt
@@ -42,11 +42,11 @@ public class DynamicObjectSerializer @OptIn(UnstableDefault::class) constructor(
public fun <T> serialize(strategy: SerializationStrategy<T>, obj: T): dynamic {
if (strategy.descriptor.kind is PrimitiveKind || strategy.descriptor.kind is UnionKind.ENUM_KIND) {
val serializer = DynamicPrimitiveEncoder(configuration)
- serializer.encode(strategy, obj)
+ serializer.encodeSerializableValue(strategy, obj)
return serializer.result
}
val serializer = DynamicObjectEncoder(configuration, encodeNullAsUndefined)
- serializer.encode(strategy, obj)
+ serializer.encodeSerializableValue(strategy, obj)
return serializer.result
}
diff --git a/runtime/jvmTest/src/kotlinx/serialization/SerializationMethodInvocationOrderTest.kt b/runtime/jvmTest/src/kotlinx/serialization/SerializationMethodInvocationOrderTest.kt
index ee5fb3ea..905ab38f 100644
--- a/runtime/jvmTest/src/kotlinx/serialization/SerializationMethodInvocationOrderTest.kt
+++ b/runtime/jvmTest/src/kotlinx/serialization/SerializationMethodInvocationOrderTest.kt
@@ -17,11 +17,11 @@ class SerializationMethodInvocationOrderTest {
@Test
fun testRec() {
val out = Out()
- out.encode(serializer(), Container(Data("s1", 42)))
+ out.encodeSerializableValue(serializer(), Container(Data("s1", 42)))
out.done()
val inp = Inp()
- inp.decode(serializer<Container>())
+ inp.decodeSerializableValue(serializer<Container>())
inp.done()
}
diff --git a/runtime/jvmTest/src/kotlinx/serialization/SerializeFlatTest.kt b/runtime/jvmTest/src/kotlinx/serialization/SerializeFlatTest.kt
index be73b6c3..619e4b96 100644
--- a/runtime/jvmTest/src/kotlinx/serialization/SerializeFlatTest.kt
+++ b/runtime/jvmTest/src/kotlinx/serialization/SerializeFlatTest.kt
@@ -87,7 +87,7 @@ object CustomSerializer : KSerializer<Custom> {
val value1 = decoder.decodeStringElement(descriptor, 0)
if (decoder.decodeElementIndex(descriptor) != 1) throw java.lang.IllegalStateException()
val value2 = decoder.decodeIntElement(descriptor, 1)
- if (decoder.decodeElementIndex(descriptor) != CompositeDecoder.READ_DONE) throw java.lang.IllegalStateException()
+ if (decoder.decodeElementIndex(descriptor) != CompositeDecoder.DECODE_DONE) throw java.lang.IllegalStateException()
decoder.endStructure(descriptor)
return Custom(value1, value2)
}
@@ -110,11 +110,11 @@ class SerializeFlatTest() {
@Test
fun testData() {
val out = Out("Data")
- out.encode(serializer(), Data("s1", 42))
+ out.encodeSerializableValue(serializer(), Data("s1", 42))
out.done()
val inp = Inp("Data")
- val data = inp.decode(serializer<Data>())
+ val data = inp.decodeSerializableValue(serializer<Data>())
inp.done()
assert(data.value1 == "s1" && data.value2 == 42)
}
@@ -122,11 +122,11 @@ class SerializeFlatTest() {
@Test
fun testDataExplicit() {
val out = Out("DataExplicit")
- out.encode(serializer(), DataExplicit("s1", 42))
+ out.encodeSerializableValue(serializer(), DataExplicit("s1", 42))
out.done()
val inp = Inp("DataExplicit")
- val data = inp.decode(serializer<DataExplicit>())
+ val data = inp.decodeSerializableValue(serializer<DataExplicit>())
inp.done()
assert(data.value1 == "s1" && data.value2 == 42)
}
@@ -137,11 +137,11 @@ class SerializeFlatTest() {
val reg = Reg()
reg.value1 = "s1"
reg.value2 = 42
- out.encode(serializer(), reg)
+ out.encodeSerializableValue(serializer(), reg)
out.done()
val inp = Inp("Reg")
- val data = inp.decode(serializer<Reg>())
+ val data = inp.decodeSerializableValue(serializer<Reg>())
inp.done()
assert(data.value1 == "s1" && data.value2 == 42)
}
@@ -149,11 +149,11 @@ class SerializeFlatTest() {
@Test
fun testNames() {
val out = Out("Names")
- out.encode(serializer(), Names("s1", 42))
+ out.encodeSerializableValue(serializer(), Names("s1", 42))
out.done()
val inp = Inp("Names")
- val data = inp.decode(serializer<Names>())
+ val data = inp.decodeSerializableValue(serializer<Names>())
inp.done()
assert(data.custom1 == "s1" && data.custom2 == 42)
}
@@ -161,11 +161,11 @@ class SerializeFlatTest() {
@Test
fun testCustom() {
val out = Out("Custom")
- out.encode(CustomSerializer, Custom("s1", 42))
+ out.encodeSerializableValue(CustomSerializer, Custom("s1", 42))
out.done()
val inp = Inp("Custom")
- val data = inp.decode(CustomSerializer)
+ val data = inp.decodeSerializableValue(CustomSerializer)
inp.done()
assert(data._value1 == "s1" && data._value2 == 42)
}
@@ -173,11 +173,11 @@ class SerializeFlatTest() {
@Test
fun testExternalData() {
val out = Out("ExternalData")
- out.encode(ExternalSerializer, ExternalData("s1", 42))
+ out.encodeSerializableValue(ExternalSerializer, ExternalData("s1", 42))
out.done()
val inp = Inp("ExternalData")
- val data = inp.decode(ExternalSerializer)
+ val data = inp.decodeSerializableValue(ExternalSerializer)
inp.done()
assert(data.value1 == "s1" && data.value2 == 42)
}
diff --git a/runtime/jvmTest/src/kotlinx/serialization/privateclasstest/PrivateDataOutOfKotlinXSerializationPackageTest.kt b/runtime/jvmTest/src/kotlinx/serialization/privateclasstest/PrivateDataOutOfKotlinXSerializationPackageTest.kt
index 0efdf2bb..119b9deb 100644
--- a/runtime/jvmTest/src/kotlinx/serialization/privateclasstest/PrivateDataOutOfKotlinXSerializationPackageTest.kt
+++ b/runtime/jvmTest/src/kotlinx/serialization/privateclasstest/PrivateDataOutOfKotlinXSerializationPackageTest.kt
@@ -36,11 +36,11 @@ class PrivateClassOutOfSerializationLibraryPackageTest {
@Test
fun testDataPrivate() {
val out = Out("privateclasstest.DataPrivate")
- out.encode(serializer(), DataPrivate("s1", 42))
+ out.encodeSerializableValue(serializer(), DataPrivate("s1", 42))
out.done()
val inp = Inp("privateclasstest.DataPrivate")
- val data = inp.decode(serializer<DataPrivate>())
+ val data = inp.decodeSerializableValue(serializer<DataPrivate>())
inp.done()
assert(data.value1 == "s1" && data.value2 == 42)
}