Skip to content

Commit

Permalink
Remove lossy "MarshalJSON" implementations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brandur authored and remi-stripe committed Sep 25, 2019
1 parent 75da7dd commit 8fcef35
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 36 deletions.
5 changes: 0 additions & 5 deletions balancetransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 0 additions & 8 deletions payout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 0 additions & 8 deletions recipienttransfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 0 additions & 8 deletions transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
11 changes: 4 additions & 7 deletions transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8fcef35

Please sign in to comment.