From 7a4630f2fcc04c7b5ad5914cd90a8f819cadd361 Mon Sep 17 00:00:00 2001 From: Brandur Date: Mon, 16 Sep 2019 16:14:23 -0700 Subject: [PATCH] Remove lossy "MarshalJSON" implementations See #946 for context, but we're removing some `MarshalJSON` implementations that are "lossy" in that they throw out information that might be useful to somebody. Note that we don't actually marshal API resources as part of normal operations in stripe-go, so the only users that this will affect are those that are manually re-marshaling resources to JSON in their integrations. --- balancetransaction.go | 5 ----- payout.go | 8 -------- recipienttransfer.go | 8 -------- transfer.go | 8 -------- transfer_test.go | 11 ++++------- 5 files changed, 4 insertions(+), 36 deletions(-) diff --git a/balancetransaction.go b/balancetransaction.go index a77666a740..f15a1a5b1c 100644 --- a/balancetransaction.go +++ b/balancetransaction.go @@ -186,8 +186,3 @@ func (s *BalanceTransactionSource) UnmarshalJSON(data []byte) error { return err } - -// MarshalJSON handles serialization of a BalanceTransactionSource. -func (s *BalanceTransactionSource) MarshalJSON() ([]byte, error) { - return json.Marshal(s.ID) -} diff --git a/payout.go b/payout.go index fcc8af26d6..4126ae513f 100644 --- a/payout.go +++ b/payout.go @@ -182,11 +182,3 @@ func (d *PayoutDestination) UnmarshalJSON(data []byte) error { return err } - -// MarshalJSON handles serialization of a PayoutDestination. -// This custom marshaling is needed because we can only send a string -// ID as a destination, even though it can be expanded to a full -// object when retrieving -func (d *PayoutDestination) MarshalJSON() ([]byte, error) { - return json.Marshal(d.ID) -} diff --git a/recipienttransfer.go b/recipienttransfer.go index b6f6482fd7..854beec81c 100644 --- a/recipienttransfer.go +++ b/recipienttransfer.go @@ -153,11 +153,3 @@ func (d *RecipientTransferDestination) UnmarshalJSON(data []byte) error { return err } - -// MarshalJSON handles serialization of a RecipientTransferDestination. -// This custom marshaling is needed because we can only send a string -// ID as a destination, even though it can be expanded to a full -// object when retrieving -func (d *RecipientTransferDestination) MarshalJSON() ([]byte, error) { - return json.Marshal(d.ID) -} diff --git a/transfer.go b/transfer.go index ef61de580b..3616a56c03 100644 --- a/transfer.go +++ b/transfer.go @@ -108,11 +108,3 @@ func (d *TransferDestination) UnmarshalJSON(data []byte) error { *d = TransferDestination(v) return json.Unmarshal(data, &d.Account) } - -// MarshalJSON handles serialization of a TransferDestination. -// This custom marshaling is needed because we can only send a string -// ID as a destination, even though it can be expanded to a full -// object when retrieving -func (d *TransferDestination) MarshalJSON() ([]byte, error) { - return json.Marshal(d.ID) -} diff --git a/transfer_test.go b/transfer_test.go index de1d06a465..5dc6dea38a 100644 --- a/transfer_test.go +++ b/transfer_test.go @@ -39,14 +39,11 @@ func TestTransferDestination_UnmarshalJSON(t *testing.T) { // Unmarshals from a JSON object { - // We build the JSON object manually here because TransferDestination - // has a custom MarshalJSON implementation as well, and it'll turn into - // a string if we marshaled a struct instance. This ensures that we're - // working with a JSON objects. - data := []byte(`{"id":"acct_123"}`) + v := TransferDestination{ID: "acct_123"} + data, err := json.Marshal(&v) + assert.NoError(t, err) - var v TransferDestination - err := json.Unmarshal(data, &v) + err = json.Unmarshal(data, &v) assert.NoError(t, err) assert.Equal(t, "acct_123", v.ID)