diff --git a/currency/pair_methods.go b/currency/pair_methods.go index 841c219f..6ec9a5ea 100644 --- a/currency/pair_methods.go +++ b/currency/pair_methods.go @@ -34,6 +34,11 @@ func (p *Pair) UnmarshalJSON(d []byte) error { return err } + if pair == "" { + *p = EMPTYPAIR + return nil + } + newPair, err := NewPairFromString(pair) if err != nil { return err diff --git a/currency/pair_test.go b/currency/pair_test.go index afa40bfe..001df884 100644 --- a/currency/pair_test.go +++ b/currency/pair_test.go @@ -70,6 +70,22 @@ func TestPairUnmarshalJSON(t *testing.T) { t.Errorf("Pairs UnmarshalJSON() error expected %s but received %s", configPair, unmarshalHere) } + + encoded, err = json.Marshal(EMPTYPAIR) + if err != nil { + t.Fatal(err) + } + err = json.Unmarshal(encoded, &unmarshalHere) + if err != nil { + t.Fatal("Pair UnmarshalJSON() error", err) + } + err = json.Unmarshal([]byte("null"), &unmarshalHere) + if err != nil { + t.Fatal("Pair UnmarshalJSON() error", err) + } + if unmarshalHere != EMPTYPAIR { + t.Fatalf("Expected EMPTYPAIR got: %s", unmarshalHere) + } } func TestPairMarshalJSON(t *testing.T) {