@@ -173,7 +173,8 @@ package to create a codec for your ``@Serializable`` data classes and
173
173
customize what is stored.
174
174
175
175
Use the ``BsonConfiguration`` class to define the configuration,
176
- including whether to encode defaults, encode nulls, or define class discriminators.
176
+ including whether to encode defaults, encode nulls, define class discriminators,
177
+ or enforce snake case.
177
178
178
179
To create a custom codec, install the ``bson-kotlinx``
179
180
dependency to your project. Select from the following tabs to see how to
@@ -241,12 +242,28 @@ The following example shows how to create a codec using the
241
242
.. literalinclude:: /examples/generated/KotlinXSerializationTest.snippet.custom-serialization.kt
242
243
:language: kotlin
243
244
245
+ Enforcing Snake Case Naming Example
246
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
247
+
248
+ The following example shows how to convert field names from their data class
249
+ fields into snake case by setting the ``bsonNamingStrategy`` parameter:
250
+
251
+ .. code-block:: kotlin
252
+ :copyable: true
253
+
254
+ import org.bson.codecs.kotlinx.BsonConfiguration
255
+ import org.bson.codecs.kotlinx.BsonNamingStrategy
256
+
257
+ .. literalinclude:: /examples/generated/KotlinXSerializationTest.snippet.snake-case-serialization.kt
258
+ :language: kotlin
259
+
244
260
For more information about the methods and classes mentioned in this section,
245
261
see the following API documentation:
246
262
247
263
- `KotlinSerializerCodec <{+api-root+}/bson-kotlinx/bson-kotlinx/org.bson.codecs.kotlinx/-kotlin-serializer-codec/index.html>`__
248
264
- `KotlinSerializerCodec.create() <{+api-root+}/bson-kotlinx/bson-kotlinx/org.bson.codecs.kotlinx/-kotlin-serializer-codec/-companion/create.html>`__
249
265
- `BsonConfiguration <{+api-root+}/bson-kotlinx/bson-kotlinx/org.bson.codecs.kotlinx/-bson-configuration/index.html>`__
266
+ - `BsonNamingStrategy <{+api-root+}/bson-kotlinx/bson-kotlinx/org.bson.codecs.kotlinx/-bson-naming-strategy/index.html>`__
250
267
251
268
.. _kotlin-polymorphic:
252
269
0 commit comments