Created
November 14, 2020 23:06
-
-
Save mikechambers/e00256003a48aa9f173f9b013e4fcc88 to your computer and use it in GitHub Desktop.
Custom JSON property Deserialization in Rust with Serde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Serialize, Deserialize, Debug)] | |
struct ManifestInfo { | |
version:String, | |
#[serde(rename(serialize = "url", deserialize = "mobileWorldContentPaths"), alias="url", deserialize_with = "deserialize_mobile_world_content_Paths")] | |
url:String, | |
} | |
fn deserialize_mobile_world_content_Paths<'de, D>(deserializer: D) -> Result<String, D::Error> where D: serde::de::Deserializer<'de> | |
{ | |
#[derive(Deserialize)] | |
#[serde (rename="mobileWorldContentPaths")] | |
struct MobileWorldContentPaths { | |
en: String, | |
} | |
//TODO: move to URL base to constant | |
MobileWorldContentPaths::deserialize(deserializer).map(|mobileWorldContentPaths| format!("https://www.bungie.net{}",mobileWorldContentPaths.en)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment