Generate UnmarshalJSON to handle emptyStringInt types
This commit changes the code generator to generate a `UnmarshalJSON` for each struct, so that if unmarshalled it properly handles UniFis varying integer values via the `emptyStringInt` type. Structs not including a field of `int` type will still have the function generated, but it will effectively do nothing. Fixes #18
This commit is contained in:
committed by
Paul Tyng
parent
c5ff8c8593
commit
4aed7d703d
@@ -51,6 +51,19 @@ func TestNetworkUnmarshalJSON(t *testing.T) {
|
||||
expected: unifi.Network{WANEgressQOS: 0},
|
||||
json: `{ "wan_egress_qos": "" }`,
|
||||
},
|
||||
|
||||
"int wan_vlan": {
|
||||
expected: unifi.Network{WANVLAN: 1},
|
||||
json: `{ "wan_vlan": 1 }`,
|
||||
},
|
||||
"string wan_vlan": {
|
||||
expected: unifi.Network{WANVLAN: 1},
|
||||
json: `{ "wan_vlan": "1" }`,
|
||||
},
|
||||
"empty wan_vlan vlan": {
|
||||
expected: unifi.Network{WANVLAN: 0},
|
||||
json: `{ "wan_vlan": "" }`,
|
||||
},
|
||||
} {
|
||||
t.Run(n, func(t *testing.T) {
|
||||
var actual unifi.Network
|
||||
|
||||
Reference in New Issue
Block a user