File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Expand file tree Collapse file tree 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 {
381381 ) ) ;
382382 }
383383
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+
384392 "$code" => {
385393 let code = visitor. next_value :: < String > ( ) ?;
386394 if let Some ( key) = visitor. next_key :: < String > ( ) ? {
Original file line number Diff line number Diff line change @@ -188,7 +188,7 @@ impl Binary {
188188#[ serde( deny_unknown_fields) ]
189189pub ( crate ) struct Uuid {
190190 #[ serde( rename = "$uuid" ) ]
191- value : String ,
191+ pub ( crate ) value : String ,
192192}
193193
194194impl Uuid {
Original file line number Diff line number Diff line change @@ -650,6 +650,21 @@ fn test_serde_legacy_uuid_1() {
650650 assert_eq ! ( foo. csharp_legacy, uuid) ;
651651}
652652
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+
653668#[ test]
654669fn test_de_oid_string ( ) {
655670 let _guard = LOCK . run_concurrently ( ) ;
You can’t perform that action at this time.
0 commit comments