Skip to content

Conversation

@daniCsorbaJB
Copy link

This is the fourth part of the Kotlin Serialization rewrite task.

Related YouTract ticket is here: KT-81889 [Docs] Create a Serialize classes page for kotlinx.serialization

Copy link
Member

@sandwwraith sandwwraith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@@ -0,0 +1,505 @@
[//]: # (title: Serialize classes)

The [`@Serializable`](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-serializable/) annotation in Kotlin enables the serialization of all properties in classes defined by the primary constructor.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, good point - changed it to properties with backing fields here as well 👍

@@ -0,0 +1,505 @@
[//]: # (title: Serialize classes)

The [`@Serializable`](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-serializable/) annotation in Kotlin enables the serialization of all properties in classes defined by the primary constructor.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, good point - changed it to properties with backing fields here as well 👍

Copy link
Member

@sandwwraith sandwwraith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know whether we'll finish whole review before mid-December (I expect next release of serialization there), but we can leave opt-in note for now and delete it later.

Besides that, please fix "Defines..." wording and my other comment and we're good to go

Copy link

@sarahhaggarty sarahhaggarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I have some suggestions for you to consider and a couple clarification questions :)

```
{kotlin-runnable="true" id="serialize-annotation-example"}

### Serialization of class references

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about "Serialize class references" as a header? So that the header style matches the others on the page?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header (and the ones below) provide specifics as to how specific kinds of elements (attributes) are handled, but this is not an active user thing. As such the verb "serialize" is misleading.

Copy link

@sarahhaggarty sarahhaggarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking great! Just two more suggestions to add links to our other content for backing fields and secondary constructors. Otherwise, LGTM! 🚀

@@ -0,0 +1,519 @@
[//]: # (title: Serialize classes)

The [`@Serializable`](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-serializable/) annotation enables the default serialization of all class properties with backing fields.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a link to our content on backing fields? https://kotlinlang.org/docs/properties.html#backing-fields

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh it's added it to the second mention 😅 — moved it to first mention! 👍


A class annotated with `@Serializable` must declare all parameters in its primary constructor as properties.

If you need to perform additional initialization logic before assigning values to properties, use a secondary constructor.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's link to our content on secondary constructors:
https://kotlinlang.org/docs/classes.html#secondary-constructors

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice good idea — added it 👍

@daniCsorbaJB daniCsorbaJB merged commit eb5f27d into doc-restructuring-master Nov 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants