File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -229,22 +229,22 @@ encode defaults:
229
229
230
230
.. _kotlin-sync-serialization-snake-case-eg:
231
231
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:
234
240
235
- The following example shows how to convert field names from their data class
236
- fields into snake case by setting the ``bsonNamingStrategy`` parameter:
237
241
238
242
.. literalinclude:: /includes/data-formats/serialization.kt
239
243
:language: kotlin
240
244
:start-after: start-snake-case
241
245
:end-before: end-snake-case
242
246
:dedent:
243
247
244
- .. note::
245
-
246
- The ``bsonNamingStrategy`` parameter is available for bson-kotlinx v5.4 and later.
247
-
248
248
To learn more about the methods and classes mentioned in this section,
249
249
see the following API documentation:
250
250
Original file line number Diff line number Diff line change @@ -105,6 +105,10 @@ fun main() {
105
105
val myCustomCodec = KotlinSerializerCodec .create<PaintOrder >(
106
106
bsonConfiguration = BsonConfiguration (bsonNamingStrategy = BsonNamingStrategy .SNAKE_CASE )
107
107
)
108
+
109
+ val registry = CodecRegistries .fromRegistries(
110
+ CodecRegistries .fromCodecs(myCustomCodec), collection.codecRegistry
111
+ )
108
112
// end-snake-case
109
113
110
114
// start-poly-operations
You can’t perform that action at this time.
0 commit comments