Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serde_with SerializeAs & DeserializeAs support for time crate #427

Closed
felschr opened this issue Aug 23, 2023 · 2 comments
Closed

serde_with SerializeAs & DeserializeAs support for time crate #427

felschr opened this issue Aug 23, 2023 · 2 comments
Assignees
Labels

Comments

@felschr
Copy link

felschr commented Aug 23, 2023

Versions/Environment

  1. What version of Rust are you using? rustc 1.71.1 (eb26296b5 2023-08-03)
  2. What operating system are you using? NixOS 23.05 (Linux)
  3. What versions of the driver and its dependencies are you using? mongodb@2.6.0 & bson@2.6.1

Describe the bug

serde_with's DeserializeAs & SerializeAs are currently only implemented for chrono. It would be nice to see them supported for time's OffsetDateTime & PrimitiveDateTime as well.

To Reproduce

use serde::{Deserialize, Serialize};
use serde_with::serde_as;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Banana {
    #[serde_as(as = "Option<bson::DateTime>")]
    pub expires: Option<time::OffsetDateTime>,
}

Additional Notes
Because proper support for serde_with is missing, I'm currently using:

#[serde(with = "bson::serde_helpers::time_0_3_offsetdatetime_as_bson_datetime")]

But this doesn't work when my OffsetDateTime is wrapped in an Option like in the example above.
Is there another way to achieve this right now before full with_serde support is implemented?

@felschr
Copy link
Author

felschr commented Aug 23, 2023

Oh, I just saw that support has recently been implemented on main for time::OffsetDateTime: 09a8cbb

Guess we'll just have to wait for a new release then.

Not sure if it makes sense to implement it for PrimitiveDateTime as well (I haven't used it yet myself), but if it does that would also be nice to have.

@isabelatkinson
Copy link
Contributor

Hi @felschr, we will likely be doing a bson release this week, so this functionality will be available then. Feel free to file a ticket in our Jira project if you would be interested in PrimitiveDateTime support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants