Skip to content

Commit 957061e

Browse files
committed
DOCSP-28748: bson-kotlin dependency (#147)
* fix link * fix link * DOCSP-28748: bson-kotlin note * vale fix * JS PR fix (cherry picked from commit a5cbf35)
1 parent fdfea7b commit 957061e

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

source/fundamentals/data-formats/serialization.txt

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
Kotlin Serialization
55
====================
66

7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: code example, data model, conversion
13+
714
.. contents:: On this page
815
:local:
916
:backlinks: none
@@ -13,23 +20,26 @@ Kotlin Serialization
1320
Overview
1421
--------
1522

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.
1825

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
2027
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.
2533

2634
.. note::
2735

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.
3343

3444
Although you can use the Kotlin driver with the Kotlin serialization ``Json``
3545
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
162172
<version>{+full-version+}</version>
163173
</dependency>
164174

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
185+
``bson-kotlinx`` library for codec configuration.
186+
187+
Then, you can define your codec using the
188+
`KotlinSerializerCodec.create()
189+
<{+api+}/apidocs/bson-kotlinx/bson-kotlinx/org.bson.codecs.kotlinx/-kotlin-serializer-codec/-companion/index.html>`__
190+
method and add it to the registry.
167191

168192
The following example shows how to create a codec using the
169193
``KotlinSerializerCodec.create()`` method and configure it to not encode defaults:

0 commit comments

Comments
 (0)