Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/de/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ impl<'de> Visitor<'de> for BsonVisitor {
));
}

"$uuid" => {
let v: String = visitor.next_value()?;
let uuid = extjson::models::Uuid { value: v }
.parse()
.map_err(Error::custom)?;
return Ok(Bson::Binary(uuid));
}

"$code" => {
let code = visitor.next_value::<String>()?;
if let Some(key) = visitor.next_key::<String>()? {
Expand Down
2 changes: 1 addition & 1 deletion src/extjson/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl Binary {
#[serde(deny_unknown_fields)]
pub(crate) struct Uuid {
#[serde(rename = "$uuid")]
value: String,
pub(crate) value: String,
}

impl Uuid {
Expand Down
15 changes: 15 additions & 0 deletions src/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,21 @@ fn test_serde_legacy_uuid_1() {
assert_eq!(foo.csharp_legacy, uuid);
}

#[test]
fn test_de_uuid_extjson_string() {
let _guard = LOCK.run_concurrently();

let uuid_bson_bytes =
hex::decode("1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400").unwrap();
let uuid_document = Document::from_reader(uuid_bson_bytes.as_slice()).unwrap();
let expected_uuid_bson = Bson::from_extended_document(uuid_document);

let ext_json_uuid = "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}";
let actual_uuid_bson: Bson = serde_json::from_str(ext_json_uuid).unwrap();

assert_eq!(actual_uuid_bson, expected_uuid_bson);
}

#[test]
fn test_de_oid_string() {
let _guard = LOCK.run_concurrently();
Expand Down