Open
Description
Here's an example of a collection with records expiring by expires_at
:
#[collection = "subscriptions"]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Subscription {
#[serde(rename = "_id")]
pub id: Option<ObjectId>,
pub expires_at: DateTime<Utc>,
}
In order for that to work I need to use the Bson::UtcDateTime helper (now DateTime), but in that case when I deliver this model to the frontend I end up with
"expires_at": {
"$date": {
"$numberLong": 1591700287095
}
},
instead of proper date. The approach with duplicating the object just for the sake date serialization is not the most convenient one.
What would be nice to have is some sort of annotation that would tell Bson Encoder/Decoder that this DateTime field has to be de/serialized as Bson date, while serde_json will serialize it as usual.
The same applies to ObjectId, currently if one wants a readable hex string instead of a json object there's a lot of duplication involved.