Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions docs-website/topics/serialization-serialize-builtin-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ fun main() {
```
{kotlin-runnable="true"}

> Unsigned numbers are currently only supported in the JSON format.
> Other formats such as ProtoBuf and CBOR serialize these types using their signed counterparts internally.
> Although JSON preserves the full range of unsigned numbers, other serialization formats may handle them differently.
> For example, ProtoBuf and CBOR serialize these types using their signed counterparts.
>
{style="note"}

Expand Down Expand Up @@ -200,7 +200,7 @@ fun main() {

### Collections

Kotlin Serialization supports collection types, including both immutable and mutable variants of [`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/), [`Set`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-set/), and [`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/).
Kotlin Serialization supports collection types, including both read-only and mutable variants of [`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/), [`Set`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-set/), and [`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/).
It also supports their concrete implementations such as [`ArrayList`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-array-list/) and [`LinkedHashSet`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-linked-hash-set/), as well as generic and primitive array types.
The way these collections are represented depends on the serialization format.

Expand Down Expand Up @@ -259,7 +259,7 @@ fun main() {
```
{kotlin-runnable="true"}

> By default, you can deserialize sets with duplicate entries. The behavior for handling duplicates depends on the specific `Set` implementation.
> By default, you can deserialize sets with duplicate entries. The behavior for handling duplicates is implementation-defined.

Choose a reason for hiding this comment

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

By "implementation-defined" do you mean that developers need to write some code for that?

>
{style="tip"}

Expand Down Expand Up @@ -288,7 +288,9 @@ fun main() {
```
{kotlin-runnable="true"}

Map serialization depends on the format.
In JSON, maps are represented as objects. Since JSON object keys are always strings, keys are encoded as strings even if they are numbers in Kotlin.
Other formats, such as CBOR, support maps with non-primitive or object keys and preserve them as such.

> JSON doesn't natively support complex or composite keys.
> To encode structured objects as map keys, see [Encode structured map keys](serialization-json-configuration.md#encode-structured-map-keys).
Copy link
Member

Choose a reason for hiding this comment

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

You can also add

Other formats may represent Maps with object keys in a more natural ways.

Copy link
Author

Choose a reason for hiding this comment

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

Hmm 🤔 this one feels a bit fluffy to me, could you please clarify? what do we mean naturally?
I think we could mention something specific like CBOR? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Kotlin's Map representation is dependent on the format. If a format supports Maps with non-primitive keys, then we can output them as such. CBOR indeed supports maps with object keys and we can use it as the example.

Copy link
Author

Choose a reason for hiding this comment

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

perfect — I added it thank you

Expand Down Expand Up @@ -331,7 +333,7 @@ fun main() {

### Unit and singleton objects

The Kotlin [`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/) type and other singleton objects are serializable.
Kotlin's [`Unit`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/) type and other singleton objects are serializable.
A [singleton](object-declarations.md) is a class with only one instance, where the state is defined by the object itself rather than by external properties.
In JSON, singleton objects are serialized as empty structures:

Expand Down Expand Up @@ -379,8 +381,8 @@ fun main() {
```
{kotlin-runnable="true"}

Similarly, Kotlin's [`Instant`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/-instant/) type
is serialized as a string representing a point in time using the ISO-8601-1 format:
Starting with Kotlin 2.2.0, you can serialize Kotlin's [`Instant`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/-instant/) type

Choose a reason for hiding this comment

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

It's best not to mention the Kotlin version this is supported in as our docs are supposed to reflect the latest stable release.

as a string representing a point in time using the ISO-8601-1 format:

```kotlin
import kotlinx.serialization.*
Expand All @@ -394,7 +396,6 @@ fun main() {
// "2020-12-09T09:16:56.124Z"
}
//sampleEnd

```
{kotlin-runnable="true" kotlin-min-compiler-version="2.2"}

Expand Down
5 changes: 5 additions & 0 deletions docs-website/topics/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ It walks you through adding the Kotlin serialization library to your project and
Kotlin serialization offers support for all platforms, including JVM, JavaScript, and Native.
You can use the same [dependency declaration](serialization-get-started.md#add-plugins-and-dependencies-for-kotlin-serialization) regardless of the target platform.

> When you’re not using a specific format library, for example, when you're writing your own serialization format,
> use the `kotlinx-serialization-core` library as the dependency.
>
{style="tip"}

Kotlin serialization supports various serialization formats, such as JSON, CBOR, and Protocol buffers through different serialization format libraries.
These libraries build on the core `kotlinx.serialization` library.
For the complete list of supported serialization formats, see [Supported serialization formats](#supported-serialization-formats).
Expand Down