Skip to content

Commit 0b3db3e

Browse files
committed
RR feedback
1 parent 4187c9e commit 0b3db3e

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

source/data-formats/serialization.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,22 @@ encode defaults:
229229

230230
.. _kotlin-sync-serialization-snake-case-eg:
231231

232-
Enforcing Snake Case Naming Example
233-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232+
Implement Snake Case Naming Strategy
233+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234+
235+
When using ``bson-kotlinx`` package v5.4 or later, you can direct the driver to
236+
serialize data class fields names written in camel case to snake case in MongoDB.
237+
The following example shows how to create and register a custom codec
238+
to convert data class field names into snake case by setting the
239+
``bsonNamingStrategy`` parameter in a codec:
234240

235-
The following example shows how to convert field names from their data class
236-
fields into snake case by setting the ``bsonNamingStrategy`` parameter:
237241

238242
.. literalinclude:: /includes/data-formats/serialization.kt
239243
:language: kotlin
240244
:start-after: start-snake-case
241245
:end-before: end-snake-case
242246
:dedent:
243247

244-
.. note::
245-
246-
The ``bsonNamingStrategy`` parameter is available for bson-kotlinx v5.4 and later.
247-
248248
To learn more about the methods and classes mentioned in this section,
249249
see the following API documentation:
250250

source/includes/data-formats/serialization.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ fun main() {
105105
val myCustomCodec = KotlinSerializerCodec.create<PaintOrder>(
106106
bsonConfiguration = BsonConfiguration(bsonNamingStrategy = BsonNamingStrategy.SNAKE_CASE)
107107
)
108+
109+
val registry = CodecRegistries.fromRegistries(
110+
CodecRegistries.fromCodecs(myCustomCodec), collection.codecRegistry
111+
)
108112
// end-snake-case
109113

110114
// start-poly-operations

0 commit comments

Comments
 (0)