From 0526e920eb6623e30966a5f470fffc0dd788c874 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 4 Feb 2022 10:09:53 +0200 Subject: [PATCH] add dese default_for_null (#860) --- ethers-solc/src/artifacts.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ethers-solc/src/artifacts.rs b/ethers-solc/src/artifacts.rs index 3df38461..5c48602f 100644 --- a/ethers-solc/src/artifacts.rs +++ b/ethers-solc/src/artifacts.rs @@ -1697,7 +1697,7 @@ pub struct Ewasm { #[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)] pub struct StorageLayout { pub storage: Vec, - #[serde(default)] + #[serde(default, deserialize_with = "default_for_null")] pub types: BTreeMap, } @@ -1990,6 +1990,14 @@ where } } +fn default_for_null<'de, D, T>(deserializer: D) -> Result +where + D: Deserializer<'de>, + T: Deserialize<'de> + Default, +{ + Ok(Option::::deserialize(deserializer)?.unwrap_or_default()) +} + #[cfg(test)] mod tests { use super::*;