File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -757,7 +757,11 @@ export function serializeInto(
757
757
758
758
// Get the entry values
759
759
const key = entry . value [ 0 ] ;
760
- const value = entry . value [ 1 ] ;
760
+ let value = entry . value [ 1 ] ;
761
+
762
+ if ( typeof value ?. toBSON === 'function' ) {
763
+ value = value . toBSON ( ) ;
764
+ }
761
765
762
766
// Check the type of the value
763
767
const type = typeof value ;
Original file line number Diff line number Diff line change @@ -183,6 +183,15 @@ describe('toBSON', function () {
183
183
const sizeNestedToBSON = BSON . calculateObjectSize ( { a : [ 0 ] } ) ;
184
184
expect ( sizeNestedToBSON ) . to . equal ( 33 ) ;
185
185
} ) ;
186
+
187
+ it ( 'uses toBSON on values contained in a map' , ( ) => {
188
+ const map = new Map ( ) ;
189
+ map . set ( 'a' , 100 ) ;
190
+
191
+ const serializedData = BSON . serialize ( map ) ;
192
+ const deserializedData = BSON . deserialize ( serializedData ) ;
193
+ expect ( deserializedData ) . to . have . property ( 'a' , 'hello number' ) ;
194
+ } ) ;
186
195
} ) ;
187
196
188
197
it ( 'should use toBSON in calculateObjectSize' , ( ) => {
You can’t perform that action at this time.
0 commit comments