Fix empty string int marshalling in go 1.14

This commit is contained in:
Paul Tyng
2020-03-26 16:13:19 -04:00
parent d076e78005
commit f74d29bd54
5 changed files with 102 additions and 38 deletions

View File

@@ -8,23 +8,19 @@ import (
func (n *WLAN) UnmarshalJSON(b []byte) error {
type Alias WLAN
aux := &struct {
VLAN json.Number `json:"vlan"`
VLAN emptyStringInt `json:"vlan"`
*Alias
}{
Alias: (*Alias)(n),
}
err := json.Unmarshal(b, &aux)
if err != nil {
return err
}
n.VLAN = 0
if aux.VLAN.String() != "" {
vlan, err := aux.VLAN.Int64()
if err != nil {
return err
}
n.VLAN = int(vlan)
}
n.VLAN = int(aux.VLAN)
return nil
}