Don't set null values since that apparently causes Element upsetti

This commit is contained in:
Neil Alexander 2022-02-18 17:31:21 +00:00
parent fa7d24984e
commit 6d63096256
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -28,10 +28,14 @@ func (a *Action) MarshalJSON() ([]byte, error) {
return nil, fmt.Errorf("only set_tweak actions may have a value, but got kind %q", a.Kind) return nil, fmt.Errorf("only set_tweak actions may have a value, but got kind %q", a.Kind)
} }
return json.Marshal(map[string]interface{}{ m := map[string]interface{}{
string(a.Kind): a.Tweak, string(a.Kind): a.Tweak,
"value": a.Value, }
}) if a.Value != nil {
m["value"] = a.Value
}
return json.Marshal(m)
} }
func (a *Action) UnmarshalJSON(bs []byte) error { func (a *Action) UnmarshalJSON(bs []byte) error {
@ -51,7 +55,9 @@ func (a *Action) UnmarshalJSON(bs []byte) error {
} }
a.Kind = SetTweakAction a.Kind = SetTweakAction
a.Tweak = raw.SetTweak a.Tweak = raw.SetTweak
if raw.Value != nil {
a.Value = raw.Value a.Value = raw.Value
}
return nil return nil
} }