Total Lines | 28 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package mollie |
||
2 | |||
3 | import ( |
||
4 | "encoding/json" |
||
5 | ) |
||
6 | |||
7 | // ContextValues is a map of TransactionType to ContextValue. |
||
8 | type ContextValues map[TransactionType]ContextValue |
||
9 | |||
10 | // UnmarshalJSON implements the json.Unmarshaler interface on ContextValues. |
||
11 | // |
||
12 | // See: https://github.com/VictorAvelar/mollie-api-go/issues/251 |
||
13 | func (cv *ContextValues) UnmarshalJSON(data []byte) error { |
||
14 | var d map[TransactionType]ContextValue |
||
15 | |||
16 | if err := json.Unmarshal(data, &d); err != nil { |
||
17 | if _, ok := err.(*json.UnmarshalTypeError); ok { |
||
18 | *cv = make(ContextValues) |
||
19 | |||
20 | return nil |
||
21 | } |
||
22 | |||
23 | return err |
||
24 | } |
||
25 | |||
26 | *cv = ContextValues(d) |
||
27 | |||
28 | return nil |
||
29 | } |
||
30 |