From 78734b13bad57c68b648802e0d16c0c6303b47e4 Mon Sep 17 00:00:00 2001 From: Joey Sacchini Date: Fri, 9 Oct 2020 18:56:59 -0400 Subject: fix issue with serialization and deserialization of translation chat --- src/chat.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/chat.rs b/src/chat.rs index be4d5b5..3a53be8 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -425,6 +425,7 @@ impl TextComponent { #[derive(Deserialize, Serialize, Clone, Debug, PartialEq)] pub struct TranslationComponent { pub translate: String, + #[serde(skip_serializing_if = "Vec::is_empty")] pub with: Vec, #[serde(flatten)] @@ -452,7 +453,9 @@ pub struct ScoreComponent { #[derive(Deserialize, Serialize, Clone, Debug, PartialEq)] pub struct ScoreComponentObjective { pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] pub objective: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub value: Option, } @@ -946,7 +949,11 @@ impl<'de> Deserialize<'de> for Chat { Err(M::Error::custom(format!("have with but it's not an array - {:?}", raw_with))) } } else { - Err(M::Error::custom("have 'translate' but missing 'with', cannot parse")) + Ok(Chat::Translation(TranslationComponent{ + base: base.into(), + translate: translate.to_owned(), + with: Vec::default(), + })) } } else { Err(M::Error::custom(format!("have translate but it's not a string - {:?}", raw_translate))) -- cgit