-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UtcDateTime derialize from json failed #81
Comments
I don't think it is possible to convert BSON extended JSON
which is then converted to
in human readable form is: {
"id": 1,
"datetime": {
"$date": {
"$numberLong": 1505225700234
}
}
} As you can see, it is definitely not possible to be converted back to What you actually want is let foo_bson: Bson = value.into();
let foo: Foo = bson::from_bson(foo_bson).unwrap(); So, this is not a bug. Won't fix. |
Why in the world do you choice to deserialize to this ? How is this supposed to be usefull ? Could we envisage a better output format ? Like put as string, or directly put a the integer ? |
@Stargateur The let thing = Thing {
bson_datetime: bson::DateTime(Utc::now()),
chrono_datetime: Utc::now(),
};
println!("{:?}", bson::to_bson(&thing).unwrap()); This produces the following ouput:
You can see that, because The JSON format you're seeing is called Extended JSON, and it is is a standardized way to serialize BSON types in JSON without losing the type information. When serializing to non-BSON formats, |
With bson 1.2.0 there exist now the serde_helpers. You can use it like: // use serde::{Serialize, Deserialize};
// use bson::serde_helpers::chrono_datetime_as_bson_datetime;
#[derive(Serialize, Deserialize)]
struct Event {
#[serde(with = "chrono_datetime_as_bson_datetime")]
pub date: chrono::DateTime<chrono::Utc>,
} |
The text was updated successfully, but these errors were encountered: