File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,22 @@ encode defaults:
227
227
:end-before: end-codec
228
228
:dedent:
229
229
230
+ Enforcing Snake Case Naming Example
231
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232
+
233
+ The following example shows how to convert field names from their data class
234
+ fields into snake case by setting the ``bsonNamingStrategy`` parameter:
235
+
236
+ .. literalinclude:: /includes/data-formats/serialization.kt
237
+ :language: kotlin
238
+ :start-after: start-snake-case
239
+ :end-before: end-snake-case
240
+ :dedent:
241
+
242
+ .. note::
243
+
244
+ The ``bsonNamingStrategy`` parameter is available for {+driver-short+} v5.4 and later.
245
+
230
246
To learn more about the methods and classes mentioned in this section,
231
247
see the following API documentation:
232
248
@@ -238,6 +254,8 @@ see the following API documentation:
238
254
239
255
- `BsonConfiguration
240
256
<{+api-root+}/bson-kotlinx/bson-kotlinx/org.bson.codecs.kotlinx/-bson-configuration/index.html>`__
257
+
258
+ - `BsonNamingStrategy <{+api-root+}/bson-kotlinx/bson-kotlinx/org.bson.codecs.kotlinx/-bson-naming-strategy/index.html>`__
241
259
242
260
.. _kotlin-sync-polymorphic:
243
261
Original file line number Diff line number Diff line change @@ -101,6 +101,12 @@ fun main() {
101
101
)
102
102
// end-codec
103
103
104
+ // start-snake-case
105
+ val myCustomCodec = KotlinSerializerCodec .create<PaintOrder >(
106
+ bsonConfiguration = BsonConfiguration (bsonNamingStrategy = BsonNamingStrategy .SNAKE_CASE )
107
+ )
108
+ // end-snake-case
109
+
104
110
// start-poly-operations
105
111
val collection = database.getCollection<Person >(" school" )
106
112
You can’t perform that action at this time.
0 commit comments