diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs index 71161a45e5d..c5cf82d68f6 100644 --- a/src/model/channel/mod.rs +++ b/src/model/channel/mod.rs @@ -12,6 +12,7 @@ mod reaction; use std::fmt; use serde::de::{Error as DeError, Unexpected}; +use serde::ser::SerializeMap as _; pub use self::attachment::*; pub use self::channel_id::*; @@ -497,7 +498,7 @@ pub enum ForumEmoji { Name(String), } -#[derive(Serialize, Deserialize)] +#[derive(Deserialize)] struct RawForumEmoji { emoji_id: Option, emoji_name: Option, @@ -505,17 +506,19 @@ struct RawForumEmoji { impl serde::Serialize for ForumEmoji { fn serialize(&self, serializer: S) -> Result { + let mut map = serializer.serialize_map(Some(2))?; match self { - Self::Id(id) => RawForumEmoji { - emoji_id: Some(*id), - emoji_name: None, + Self::Id(id) => { + map.serialize_entry("emoji_id", id)?; + map.serialize_entry("emoji_name", &None::<()>)?; }, - Self::Name(name) => RawForumEmoji { - emoji_id: None, - emoji_name: Some(name.clone()), + Self::Name(name) => { + map.serialize_entry("emoji_id", &None::<()>)?; + map.serialize_entry("emoji_name", name)?; }, - } - .serialize(serializer) + }; + + map.end() } }