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
Select from the following tabs to see how to add the serialization
64
+
dependencies to your project by using the :guilabel:`Gradle` and
65
+
:guilabel:`Maven` package managers:
67
66
68
67
.. tabs::
69
68
@@ -106,7 +105,7 @@ To declare a class as serializable, annotate your Kotlin data classes with the
106
105
``@Serializable`` annotation from the Kotlin serialization framework.
107
106
108
107
You can use your data classes in your code as normal after you mark them as serializable.
109
-
The Kotlin driver and the Kotlin serialization framework will handle the
108
+
The {+driver-short+} and the Kotlin serialization framework handle the
110
109
BSON serialization and deserialization.
111
110
112
111
This example shows a simple data class annotated with the following:
@@ -130,6 +129,38 @@ For more information on serializable classes and available annotation classes,
130
129
see the `official Kotlin Serialization <https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/basic-serialization.md#serializable-classes>`__
131
130
documentation.
132
131
132
+
Custom Serializer Example
133
+
~~~~~~~~~~~~~~~~~~~~~~~~~
134
+
135
+
You can create a custom serializer to handle how your data is
136
+
represented in BSON. The {+driver-short+} uses the ``KSerializer``
137
+
interface from the ``kotlinx.serialization`` package to implement custom
138
+
serializers. You can specify the custom serializer as the parameter to
139
+
the ``@Serializable`` annotation for a specific field.
140
+
141
+
The following example shows how to create a custom
142
+
``KSerializer`` instance to convert a ``kotlinx.datetime.Instant`` to a
0 commit comments