Add test to verify urlencoded deserializer works with serde attributes
@@ -141,6 +141,46 @@ fn deserialize_multiple_lists() {
);
}
+#[test]
+fn deserialize_with_serde_attributes() {
+ use std::time::{Duration, SystemTime, UNIX_EPOCH};
+
+ #[derive(Debug, PartialEq, Deserialize)]
+ struct FieldsWithAttributes {
+ #[serde(default)]
+ xs: Vec<bool>,
+ #[serde(default)]
+ def: Option<u8>,
+ #[serde(
+ default,
+ deserialize_with = "ruma_serde::time::opt_ms_since_unix_epoch::deserialize"
+ )]
+ time: Option<SystemTime>,
+ #[serde(default)]
+ flag: bool,
+ }
+
+ assert_eq!(
+ urlencoded::from_str("xs=true&xs=false&def=3&time=1&flag=true"),
+ Ok(FieldsWithAttributes {
+ xs: vec![true, false],
+ def: Some(3),
+ time: Some(UNIX_EPOCH + Duration::from_millis(1)),
+ flag: true,
+ })
+ );
+
+ assert_eq!(
+ urlencoded::from_str(""),
+ Ok(FieldsWithAttributes {
+ xs: vec![],
+ def: None,
+ time: None,
+ flag: false,
+ })
+ );
+}
+
#[test]
fn deserialize_nested_list() {
assert!(urlencoded::from_str::<Vec<(&str, Vec<Vec<bool>>)>>("a=b").is_err());
