-
Notifications
You must be signed in to change notification settings - Fork 144
Any reason serializer.is_human_readable() == true
?
#297
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
Comments
Hi @fjarri, thanks for reporting this issue! For the raw BSON serializer, this was certainly an oversight and something we need to fix. For the I filed RUST-1009 to cover the work for updating the raw BSON serializer. Thanks again for reporting this! |
This was fixed in #298 and will be included in the 2.0.0 release. |
Thank you for this helpful clarification. I'd like to raise a use case where this solution is challenging: UUIDs. Specifically, I would like to be able to encode one type with multiple serializers (eg. BSON and JSON). The UUID type itself uses the The current recommended solution seems to be using the A related issue with this solution is that One of the things that's great about serde is that it (usually) allows me to solve specific encoding challenges once, directly on the type, then have it transparently behave correctly wherever it's used. This proves to be incredibly valuable as a team and codebase grows. This challenge isn't unique to BSON. UUIDs are, in general, difficult to use well with serde because so many serialization formats treat UUIDs as a special case, but serde's intermediary format doesn't carry enough information. Thank you for this very useful library. |
Thanks for the detailed comment @dgrijalva, you bring up some very good points. The mismatch between As a workaround in the meantime, you can first serialize to a let bytes = bson::to_vec(my_query)?;
let doc = Document::from_reader(bytes.as_slice())? This isn't the most performant way to do this, but it at least avoids having to write any special serialization code. Regarding the concerns of forgetting |
That all makes sense. Thanks for the update. Sounds like I just missed the cutoff. I'm glad you're sticking to the semver rules. They feel painful for scenarios like this, but it's better for the community in the long run. We put a somewhat clumsy workaround in place for now. I'll keep an eye out for |
Quick update on this: we just released e.g. #[derive(Debug, Deserialize, Serialize)]
struct MyData {
a: String,
}
let data = MyData { a: "ok".to_string() };
let options = SerializerOptions::builder().human_readable(false).build();
let bson = bson::to_bson_with_options(&data, options)?;
let options = DeserializerOptions::builder().human_readable(false).build();
let rt_data: MyData = bson::from_bson_with_options(bson, options)?; |
That seems great! We'll have a look at it. Thanks! |
I have some types naturally representable as bytestrings, and serializers for them that make use of
is_human_readable()
, encoding bytes in b64 if it istrue
and using raw bytes otherwise. I noticed that in this crateis_human_readable()
forSerializer
is not overridden, so it returnstrue
, which seems strange for a binary format. Is that intentional?The text was updated successfully, but these errors were encountered: