|
Handling of nullable ObjectId / Bson Value types fails if the type is the first in the data class and optional.
@Serializable
|
data class PaintOrder(
|
@SerialName("_id") // Use instead of @BsonId
|
@Contextual val id: ObjectId?,
|
val color: String,
|
val qty: Int,
|
@SerialName("brand")
|
val manufacturer: String = "Acme", // Use instead of @BsonProperty
|
)
|
|
|
val paintOrder = PaintOrder(ObjectId(), "red", 5, "Acme")
|
val collection = database.getCollection<PaintOrder>("orders")
|
val insertOneResult = collection.insertOne(paintOrder)
|
println(insertOneResult) // returns with expected results (e.g. "AcknowledgedInsertOneResult{insertedId=BsonObjectId{value=648b20978b3dfb1f994a2164}}")
|
val results = collection.find().firstOrNull()
|
assertEquals(results, paintOrder)
|
The following code is failing to hydrate the ObjectId even though its been decoded.
|