File tree 3 files changed +24
-1
lines changed
3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -381,6 +381,14 @@ impl<'de> Visitor<'de> for BsonVisitor {
381
381
) ) ;
382
382
}
383
383
384
+ "$uuid" => {
385
+ let v: String = visitor. next_value ( ) ?;
386
+ let uuid = extjson:: models:: Uuid { value : v }
387
+ . parse ( )
388
+ . map_err ( Error :: custom) ?;
389
+ return Ok ( Bson :: Binary ( uuid) ) ;
390
+ }
391
+
384
392
"$code" => {
385
393
let code = visitor. next_value :: < String > ( ) ?;
386
394
if let Some ( key) = visitor. next_key :: < String > ( ) ? {
Original file line number Diff line number Diff line change @@ -188,7 +188,7 @@ impl Binary {
188
188
#[ serde( deny_unknown_fields) ]
189
189
pub ( crate ) struct Uuid {
190
190
#[ serde( rename = "$uuid" ) ]
191
- value : String ,
191
+ pub ( crate ) value : String ,
192
192
}
193
193
194
194
impl Uuid {
Original file line number Diff line number Diff line change @@ -650,6 +650,21 @@ fn test_serde_legacy_uuid_1() {
650
650
assert_eq ! ( foo. csharp_legacy, uuid) ;
651
651
}
652
652
653
+ #[ test]
654
+ fn test_de_uuid_extjson_string ( ) {
655
+ let _guard = LOCK . run_concurrently ( ) ;
656
+
657
+ let uuid_bson_bytes =
658
+ hex:: decode ( "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400" ) . unwrap ( ) ;
659
+ let uuid_document = Document :: from_reader ( uuid_bson_bytes. as_slice ( ) ) . unwrap ( ) ;
660
+ let expected_uuid_bson = Bson :: from_extended_document ( uuid_document) ;
661
+
662
+ let ext_json_uuid = "{\" x\" : { \" $uuid\" : \" 73ffd264-44b3-4c69-90e8-e7d1dfc035d4\" }}" ;
663
+ let actual_uuid_bson: Bson = serde_json:: from_str ( ext_json_uuid) . unwrap ( ) ;
664
+
665
+ assert_eq ! ( actual_uuid_bson, expected_uuid_bson) ;
666
+ }
667
+
653
668
#[ test]
654
669
fn test_de_oid_string ( ) {
655
670
let _guard = LOCK . run_concurrently ( ) ;
You can’t perform that action at this time.
0 commit comments