EJSON prevents replacer from working on unsupported values

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: EJSON
    • 0
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      What problem are you facing?

      EJSON.stringify mirrors JSON.stringify and accepts a replacer that should allow non-EJSON-ifyable values to be replaced with something that is. Unfortunately the serializeValue routine is run first so information about the value is lost by the time it reached the replacer.

      The desired use case is to add a simple replacer that supports es6 Map and Set, but when the replacer is called Maps become an empty object.

      What driver and relevant dependency versions are you using?

      BSON 4.x

      Steps to reproduce?

      You can see below that in the JSON api the callback is given a reference to the Map:

      > JSON.stringify( {m: new Map()}, (k,v) => {console.log('k:', k, 'v:',v); return v;})
      k:  v: { m: Map(0) {} }
      k: m v: Map(0) {}
      '{"m":{}}'
      > BSON.EJSON.stringify( {m: new Map()}, (k,v) => {console.log('k:', k, 'v:',v); return v;})
      k:  v: { m: {} }
      k: m v: {}
      '{"m":{}}
      

              Assignee:
              Unassigned
              Reporter:
              Neal Beeken
              None
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: