time icon indicating copy to clipboard operation
time copied to clipboard

RFC3339 Option<OffsetDateTime> fails for flattened struct

Open nthuemmel-scontain opened this issue 2 years ago • 0 comments

RFC3339 Option<OffsetDateTime> parsing does not work for flattened structures. Example to reproduce:

use serde::{Deserialize, Serialize};
        use time::OffsetDateTime;

        #[derive(Serialize, Deserialize)]
        struct Nested {
            #[serde(default, with = "time::serde::rfc3339::option")]
            v1: Option<OffsetDateTime>,
            #[serde(default, with = "time::serde::rfc3339::option")]
            v2: Option<OffsetDateTime>,
            #[serde(default, with = "time::serde::rfc3339::option")]
            v3: Option<OffsetDateTime>,
        }

        #[derive(Serialize, Deserialize)]
        struct Container {
            #[serde(flatten)]
            nested: Nested,
        }

        let input = r#"
{
  "v2": null,
  "v3": "2022-02-20T22:42:42Z"
}
"#;

        let value: Container = serde_json::from_str(input).unwrap();
        let serialized = serde_json::to_string_pretty(&value).unwrap();

        assert_eq!(
            serialized,
            r#"{
  "v1": null,
  "v2": null,
  "v3": "2022-02-20T22:42:42Z"
}"#
        );
  • On time 0.3.9, this fails with invalid type: null, expected an RFC3339-formatted Option<OffsetDateTime>
  • On time 0.3.10, this fails with invalid type: Option value, expected an RFC3339-formatted OffsetDateTime (duplicate of #479)

nthuemmel-scontain avatar Jun 20 '22 14:06 nthuemmel-scontain