@@ -455,7 +455,7 @@ impl Bson {
455455 "$date" : { "$numberLong" : v. timestamp_millis( ) . to_string( ) } ,
456456 } ) ,
457457 Bson :: Symbol ( v) => json ! ( { "$symbol" : v } ) ,
458- Bson :: Decimal128 ( _ ) => panic ! ( "Decimal128 extended JSON not implemented yet." ) ,
458+ Bson :: Decimal128 ( v ) => json ! ( { "$numberDecimal" : v . to_string ( ) } ) ,
459459 Bson :: Undefined => json ! ( { "$undefined" : true } ) ,
460460 Bson :: MinKey => json ! ( { "$minKey" : 1 } ) ,
461461 Bson :: MaxKey => json ! ( { "$maxKey" : 1 } ) ,
@@ -474,9 +474,6 @@ impl Bson {
474474 }
475475
476476 /// Converts the Bson value into its [canonical extended JSON representation](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/).
477- ///
478- /// Note: extended json encoding for `Decimal128` values is not supported. If this method is
479- /// called on a case which contains a `Decimal128` value, it will panic.
480477 pub fn into_canonical_extjson ( self ) -> Value {
481478 match self {
482479 Bson :: Int32 ( i) => json ! ( { "$numberInt" : i. to_string( ) } ) ,
@@ -705,6 +702,14 @@ impl Bson {
705702 _ => { }
706703 } ,
707704
705+ [ "$numberDecimal" ] => {
706+ if let Ok ( d) = doc. get_str ( "$numberDecimal" ) {
707+ if let Ok ( d) = d. parse ( ) {
708+ return Bson :: Decimal128 ( d) ;
709+ }
710+ }
711+ }
712+
708713 [ "$numberDecimalBytes" ] => {
709714 if let Ok ( bytes) = doc. get_binary_generic ( "$numberDecimalBytes" ) {
710715 if let Ok ( b) = bytes. clone ( ) . try_into ( ) {
0 commit comments