-
Notifications
You must be signed in to change notification settings - Fork 663
Doc rewrite update 3 - Serialize built in types #3082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: doc-restructuring-master
Are you sure you want to change the base?
Changes from 1 commit
56ec279
a763a22
3f475f0
e8e7b46
dee407b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"} | ||
|
|
||
|
|
@@ -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. | ||
|
|
||
|
|
@@ -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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"} | ||
|
|
||
|
|
@@ -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. | ||
daniCsorbaJB marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| > 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). | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also add
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perfect — I added it thank you |
||
|
|
@@ -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: | ||
|
|
||
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.* | ||
|
|
@@ -394,7 +396,6 @@ fun main() { | |
| // "2020-12-09T09:16:56.124Z" | ||
| } | ||
| //sampleEnd | ||
|
|
||
| ``` | ||
| {kotlin-runnable="true" kotlin-min-compiler-version="2.2"} | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.