0.25.0 • BsonContext/BsonFactory split, serialization annotation support, experimental BsonPath and eager multiplatform BSON¶
BsonContext and BsonFactory¶
Breaking change
Impacted modules:
:bson,:dsl
Since the start of the project, the configuration of BSON documents is stored by the BsonContext interface. However, it was starting to become too big.
Initially, BsonContext was used for BSON object creation. In 0.19.0, it obtained the capability of creating ObjectId instances. In this version, it would also have obtained the configuration for serializing paths.
In this release, it is changed as follows:
- The
BsonContextis removed from:bson. - The new
BsonFactoryinterface becomes responsible from creating BSON documents. - The capability of creating new
ObjectIdinstances remains inObjectIdGenerator. - A new
BsonContextinterface is created in:dsl, which aggregates the capabilities required by the DSL.
If you created custom operators, you will need to switch the imports from the old BsonContext to the new one.
Otherwise, end-users should not be impacted.
PropertyNameStrategy¶
Impacted modules:
:dsl,:driver-sync-kmongo,:driver-coroutines-kmongo
The new interface PropertyNameStrategy was added to configure how the Foo::user / User::name syntax is converted into MongoDB paths.
Users can override the default implementation when initializing the KtMongo library.
For example, this can be used to look up annotations on the fields to change their name.
When using one of the KMongo compatibility modules, the strategy used understands @BsonId and KotlinX.Serialization's @SerialName, as recommended by the KMongo documentation for the KotlinX.Serialization library.
If you use Jackson or want to use KotlinX.Serialization annotations with the regular driver modules (without using the KMongo compatibility modules) you can override the PropertyNameStrategy used by the driver.
We do not plan to add support for serialization annotations in the default implementation.
As a consequence, some methods have been moved from Field to FieldDsl.
BsonPath¶
Experimental
Impacted modules:
:bson
Added the experimental BsonPath interface to represent JSONPath-like accessors to BSON documents.
BsonPath is a great alternative to deserialization when we are only interested in a few fields, as it avoids the need for creating complex DTOs, especially when they are deeply nested.
BSON¶
- Removed
@ExperimentalStdlibApion theObjectIdconstructor as it has been stabilized in the standard library (b9ccf073) ObjectId.Serializerhas been changed from a class to an object (88f6947e)Timestamp.Serializerhas been changed from a class to an object (88f6947e)
BSON (multiplatform)¶
- Instances of
.reader()are now reused. This will make access to fields faster (60397c9d) - Added
Bson.eager()andBsonArray.eager()to eagerly initialize the readers, which makes them thread-safe. Improved the documentation on thread-safety (!167) - Improved the documentation of
BsonandBsonArray(!167)
Dependencies¶
- Kotlin 2.2.21
Browse the documentation for this version • View release in GitLab