Uploaded image for project: 'Rust Driver'
  1. Rust Driver
  2. RUST-1024

Add serde_with integration for composable serde helpers

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • bson-2.1.0
    • Affects Version/s: None
    • Component/s: BSON
    • None

      The crate serde_with provides the SerializeAs and DeserializeAs traits, which we can implement on our types to allow for composable serde(with = "") attributes. These currently aren't supported in vanilla serde.

      This will enable the following (which currently isn't possible):

      #[serde_as]
      #[derive(Debug, Serialize, Deserialize)]
      struct MyData {
          #[serde_as(as = "Option<bson::DateTime>")
          date: Option<chrono::DateTime<Utc>>
      }
      

      And this struct will serialize to / from BSON, even though there's an Option wrapper.

      Originally reported in GH issue: https://github.com/mongodb/bson-rust/issues/303

            Assignee:
            patrick.freed@mongodb.com Patrick Freed
            Reporter:
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: