Skip to content

Commit 8be61c2

Browse files
committed
(ForumTag): implement custom JSON unmarshalling for ID field
1 parent 98dc133 commit 8be61c2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

structs.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,30 @@ type ForumTag struct {
601601
EmojiName string `json:"emoji_name,omitempty"`
602602
}
603603

604+
// Sometimes ID is a number instead of a string, so we need to unmarshal it manually
605+
func (t *ForumTag) UnmarshalJSON(data []byte) error {
606+
temp := struct {
607+
ID json.Number `json:"id,omitempty"`
608+
Name string `json:"name"`
609+
Moderated bool `json:"moderated"`
610+
EmojiID string `json:"emoji_id,omitempty"`
611+
EmojiName string `json:"emoji_name,omitempty"`
612+
}{}
613+
614+
err := json.Unmarshal(data, &temp)
615+
if err != nil {
616+
return err
617+
}
618+
619+
t.ID = temp.ID.String()
620+
t.Name = temp.Name
621+
t.Moderated = temp.Moderated
622+
t.EmojiID = temp.EmojiID
623+
t.EmojiName = temp.EmojiName
624+
625+
return nil
626+
}
627+
604628
// Emoji struct holds data related to Emoji's
605629
type Emoji struct {
606630
ID string `json:"id"`

0 commit comments

Comments
 (0)