You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/fundamentals/data-formats/serialization.txt
+38-14Lines changed: 38 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,13 @@
4
4
Kotlin Serialization
5
5
====================
6
6
7
+
.. facet::
8
+
:name: genre
9
+
:values: reference
10
+
11
+
.. meta::
12
+
:keywords: code example, data model, conversion
13
+
7
14
.. contents:: On this page
8
15
:local:
9
16
:backlinks: none
@@ -13,23 +20,26 @@ Kotlin Serialization
13
20
Overview
14
21
--------
15
22
16
-
The Kotlin driver supports the ``kotlinx.serialization`` library for serializing
17
-
and deserializing Kotlin objects.
23
+
The Kotlin driver supports the ``kotlinx.serialization`` library for
24
+
serializing and deserializing Kotlin objects.
18
25
19
-
The driver provides an efficient ``Bson`` serializer that can can be used with
26
+
The driver provides an efficient ``Bson`` serializer that you can use with
20
27
classes marked as ``@Serializable`` to handle the serialization of Kotlin objects
21
-
to BSON data.
22
-
The ``bson-kotlinx`` library also supports :ref:`custom codecs <kotlin-custom-codec>`
23
-
with configurations to encode defaults, encode nulls, and define class
24
-
discriminators.
28
+
to BSON data.
29
+
30
+
You can also install the ``bson-kotlinx`` library to support
31
+
:ref:`custom codecs <kotlin-custom-codec>` with configurations to encode
32
+
defaults, encode nulls, and define class discriminators.
25
33
26
34
.. note::
27
35
28
-
To use the ``Codec`` interface instead of the Kotlin serialization library
29
-
to specify custom encoding and decoding of Kotlin objects to BSON data,
30
-
see the :ref:`Codecs <fundamentals-codecs>` documentation. You might choose
31
-
Kotlin serialization if you are already familiar with the framework or
32
-
you prefer to use an idiomatic Kotlin approach.
36
+
To learn how to use the ``Codec`` interface instead of the
37
+
Kotlin serialization library to specify custom encoding and decoding
38
+
of Kotlin objects to BSON data, see the :ref:`Codecs
39
+
<fundamentals-codecs>` guide.
40
+
41
+
You might choose Kotlin serialization if you are already familiar
42
+
with the framework or if you prefer to use an idiomatic Kotlin approach.
33
43
34
44
Although you can use the Kotlin driver with the Kotlin serialization ``Json``
35
45
library, the ``Json`` serializer does *not* directly support BSON value types such
@@ -162,8 +172,22 @@ To create a custom codec, install the ``bson-kotlinx`` dependency to your projec
162
172
<version>{+full-version+}</version>
163
173
</dependency>
164
174
165
-
Then, you can define your codec using the `KotlinSerializerCodec.create() <apidocs/bson-kotlinx/bson-kotlinx/org.bson.codecs.kotlinx/-kotlin-serializer-codec/-companion/create.html>`__
166
-
method and add it to the registry.
175
+
.. note:: bson-kotlin Dependency
176
+
177
+
You can also optionally install the ``bson-kotlin`` dependency
178
+
through the default codec registry. This dependency uses reflection
179
+
and the codec registry to support Kotlin data classes, but it does
180
+
not support certain POJO annotations such as ``BsonDiscriminator``,
181
+
``BsonExtraElements``, and ``BsonConstructor``. To learn more, see
182
+
the `bson-kotlin API documentation <{+api+}/apidocs/bson-kotlin/index.html>`__.
183
+
184
+
Generally, we recommend that you install and use the faster
0 commit comments