diff options
author | Joey Sacchini <joey@sacchini.net> | 2020-10-09 18:56:59 -0400 |
---|---|---|
committer | Joey Sacchini <joey@sacchini.net> | 2020-10-09 18:56:59 -0400 |
commit | 78734b13bad57c68b648802e0d16c0c6303b47e4 (patch) | |
tree | bd7d87f1b296aa605808dced582855e0cdd0c6ea | |
parent | 10bbcdb2607f25ff9a0702caf7363076af521ec8 (diff) | |
download | mcproto-rs-78734b13bad57c68b648802e0d16c0c6303b47e4.tar.gz mcproto-rs-78734b13bad57c68b648802e0d16c0c6303b47e4.tar.bz2 mcproto-rs-78734b13bad57c68b648802e0d16c0c6303b47e4.zip |
fix issue with serialization and deserialization of translation chat
-rw-r--r-- | src/chat.rs | 9 |
1 files changed, 8 insertions, 1 deletions
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<BoxedChat>, #[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<String>, + #[serde(skip_serializing_if = "Option::is_none")] pub value: Option<String>, } @@ -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))) |