Skip to content

Commit 06aabd2

Browse files
authored
Fix outdated buildClassSerialDescriptor documentation (#2306)
Fixes #1434
1 parent f833852 commit 06aabd2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

core/commonMain/src/kotlinx/serialization/descriptors/SerialDescriptors.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package kotlinx.serialization.descriptors
66

77
import kotlinx.serialization.*
8+
import kotlinx.serialization.builtins.*
89
import kotlinx.serialization.encoding.*
910
import kotlinx.serialization.internal.*
1011
import kotlin.reflect.*
@@ -24,22 +25,24 @@ import kotlin.reflect.*
2425
* val nullableInt: Int?
2526
* )
2627
* // Descriptor for such class:
27-
* SerialDescriptor("my.package.Data") {
28+
* buildClassSerialDescriptor("my.package.Data") {
2829
* // intField is deliberately ignored by serializer -- not present in the descriptor as well
2930
* element<Long>("_longField") // longField is named as _longField
30-
* element("stringField", listSerialDescriptor<String>())
31+
* element("stringField", listSerialDescriptor<String>()) // or ListSerializer(String.serializer()).descriptor
3132
* element("nullableInt", serialDescriptor<Int>().nullable)
3233
* }
3334
* ```
3435
*
3536
* Example for generic classes:
3637
* ```
38+
* import kotlinx.serialization.builtins.*
39+
*
3740
* @Serializable(CustomSerializer::class)
3841
* class BoxedList<T>(val list: List<T>)
3942
*
4043
* class CustomSerializer<T>(tSerializer: KSerializer<T>): KSerializer<BoxedList<T>> {
4144
* // here we use tSerializer.descriptor because it represents T
42-
* override val descriptor = SerialDescriptor("pkg.BoxedList", CLASS, tSerializer.descriptor) {
45+
* override val descriptor = buildClassSerialDescriptor("pkg.BoxedList", tSerializer.descriptor) {
4346
* // here we have to wrap it with List first, because property has type List<T>
4447
* element("list", ListSerializer(tSerializer).descriptor) // or listSerialDescriptor(tSerializer.descriptor)
4548
* }
@@ -129,7 +132,7 @@ internal class WrappedSerialDescriptor(override val serialName: String, original
129132
* This function is left public only for migration of pre-release users and is not intended to be used
130133
* as generally-safe and stable mechanism. Beware that it can produce inconsistent or non spec-compliant instances.
131134
*
132-
* If you end up using this builder, please file an issue with your use-case in kotlinx.serialization
135+
* If you end up using this builder, please file an issue with your use-case in kotlinx.serialization issue tracker.
133136
*/
134137
@InternalSerializationApi
135138
@OptIn(ExperimentalSerializationApi::class)

0 commit comments

Comments
 (0)