Skip to content

Commit

Permalink
Fix outdated buildClassSerialDescriptor documentation (#2306)
Browse files Browse the repository at this point in the history
Fixes #1434
  • Loading branch information
sandwwraith authored May 17, 2023
1 parent f833852 commit 06aabd2
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package kotlinx.serialization.descriptors

import kotlinx.serialization.*
import kotlinx.serialization.builtins.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.internal.*
import kotlin.reflect.*
Expand All @@ -24,22 +25,24 @@ import kotlin.reflect.*
* val nullableInt: Int?
* )
* // Descriptor for such class:
* SerialDescriptor("my.package.Data") {
* buildClassSerialDescriptor("my.package.Data") {
* // intField is deliberately ignored by serializer -- not present in the descriptor as well
* element<Long>("_longField") // longField is named as _longField
* element("stringField", listSerialDescriptor<String>())
* element("stringField", listSerialDescriptor<String>()) // or ListSerializer(String.serializer()).descriptor
* element("nullableInt", serialDescriptor<Int>().nullable)
* }
* ```
*
* Example for generic classes:
* ```
* import kotlinx.serialization.builtins.*
*
* @Serializable(CustomSerializer::class)
* class BoxedList<T>(val list: List<T>)
*
* class CustomSerializer<T>(tSerializer: KSerializer<T>): KSerializer<BoxedList<T>> {
* // here we use tSerializer.descriptor because it represents T
* override val descriptor = SerialDescriptor("pkg.BoxedList", CLASS, tSerializer.descriptor) {
* override val descriptor = buildClassSerialDescriptor("pkg.BoxedList", tSerializer.descriptor) {
* // here we have to wrap it with List first, because property has type List<T>
* element("list", ListSerializer(tSerializer).descriptor) // or listSerialDescriptor(tSerializer.descriptor)
* }
Expand Down Expand Up @@ -129,7 +132,7 @@ internal class WrappedSerialDescriptor(override val serialName: String, original
* This function is left public only for migration of pre-release users and is not intended to be used
* as generally-safe and stable mechanism. Beware that it can produce inconsistent or non spec-compliant instances.
*
* If you end up using this builder, please file an issue with your use-case in kotlinx.serialization
* If you end up using this builder, please file an issue with your use-case in kotlinx.serialization issue tracker.
*/
@InternalSerializationApi
@OptIn(ExperimentalSerializationApi::class)
Expand Down

0 comments on commit 06aabd2

Please sign in to comment.