Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-341

Respect date encoding/decoding strategies when encoding/decoding to documents

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Right now, if we encode a Document with BSONEncoder, we simply return the document itself. If the user sets a non-default date encoding strategy, it gets ignored. Similar behavior is true for decoding to a Document in BSONDecoder.

      We should update encode and decode to not short circuit when the user specifies a non-default date encoding/decoding strategy, and instead use the strategies to properly encode/decode dates.

      This is important for ensuring Collection<Document>s write to the database as the user expects, not so much for the following example.

      e.g. the following should print an integer, not string representation of a Date

      let doc: Document = ["date": Date()]
      let encoder = BSONEncoder()
      encoder.dateEncodingStrategy = .millisecondsSinceEpoch
      let doc1 = encoder.encode(doc)
      print(doc1["date"]) // Int64(...)
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: