mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
fixed serialization error not returning empty string
This commit is contained in:
parent
834c54c1d6
commit
f2d98fdb8a
1 changed files with 16 additions and 5 deletions
21
src/types.rs
21
src/types.rs
|
@ -301,7 +301,10 @@ pub(crate) mod option_url_from_string {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
this.serialize(serializer)
|
||||
match this {
|
||||
Some(url) => url.serialize(serializer),
|
||||
None => "".serialize(serializer),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<Option<Url>, D::Error>
|
||||
|
@ -322,15 +325,23 @@ pub(crate) mod option_url_from_string {
|
|||
|
||||
{
|
||||
let json = r#"{"url":""}"#;
|
||||
let Struct { url } = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(url, None);
|
||||
let url: Struct = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(url.url, None);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&url).unwrap(),
|
||||
r#"{"url":""}"#.to_string()
|
||||
);
|
||||
|
||||
let json = r#"{"url":"https://github.com/token"}"#;
|
||||
let Struct { url } = serde_json::from_str(json).unwrap();
|
||||
let url: Struct = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(
|
||||
url,
|
||||
url.url,
|
||||
Some(Url::from_str("https://github.com/token").unwrap())
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&url).unwrap(),
|
||||
r#"{"url":"https://github.com/token"}"#.to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue