Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions source/data-formats/serialization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,24 @@ encode defaults:
:end-before: end-codec
:dedent:

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

Enforcing Snake Case Naming Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: remove extra line

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

.. literalinclude:: /includes/data-formats/serialization.kt
:language: kotlin
:start-after: start-snake-case
:end-before: end-snake-case
:dedent:

.. note::

The ``bsonNamingStrategy`` parameter is available for bson-kotlinx v5.4 and later.

To learn more about the methods and classes mentioned in this section,
see the following API documentation:

Expand All @@ -238,6 +256,8 @@ see the following API documentation:

- `BsonConfiguration
<{+api-root+}/bson-kotlinx/bson-kotlinx/org.bson.codecs.kotlinx/-bson-configuration/index.html>`__

- `BsonNamingStrategy <{+api-root+}/bson-kotlinx/bson-kotlinx/org.bson.codecs.kotlinx/-bson-naming-strategy/index.html>`__

.. _kotlin-sync-polymorphic:

Expand Down
6 changes: 6 additions & 0 deletions source/includes/data-formats/serialization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ fun main() {
)
// end-codec

// start-snake-case
val myCustomCodec = KotlinSerializerCodec.create<PaintOrder>(
bsonConfiguration = BsonConfiguration(bsonNamingStrategy = BsonNamingStrategy.SNAKE_CASE)
)
// end-snake-case

// start-poly-operations
val collection = database.getCollection<Person>("school")

Expand Down
4 changes: 4 additions & 0 deletions source/whats-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ What's New in 5.4
The 5.4 driver release includes the following changes, fixes,
and features:

- Adds support for converting field names to snake case during serialization. To
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: consider bumping this out into a "Serialization Features" subheading

learn more, see the :ref:`kotlin-sync-serialization-snake-case-eg` on the
Serialization page.

.. sharedinclude:: dbx/jvm/v5.4-wn-items.rst

.. replacement:: install-bom-link
Expand Down
Loading