Skip to content

Commit

Permalink
ref: Simplify MarshalJSON implementations (#242)
Browse files Browse the repository at this point in the history
There is no need to embed the alias type in a struct when the aliased
type is already a struct itself and there are no new/shadowed fields.

A type conversion does the job of triggering the default json.Marshal
behavior.
  • Loading branch information
rhcarvalho authored Jun 3, 2020
1 parent af3076c commit 13e3ab1
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ func (b *Breadcrumb) MarshalJSON() ([]byte, error) {
alias: (*alias)(b),
})
}
return json.Marshal(&struct {
*alias
}{
alias: (*alias)(b),
})
return json.Marshal((*alias)(b))
}

// https://docs.sentry.io/development/sdk-dev/event-payloads/user/
Expand Down Expand Up @@ -184,11 +180,7 @@ func (e *Event) MarshalJSON() ([]byte, error) {
alias: (*alias)(e),
})
}
return json.Marshal(&struct {
*alias
}{
alias: (*alias)(e),
})
return json.Marshal((*alias)(e))
}

func NewEvent() *Event {
Expand Down

0 comments on commit 13e3ab1

Please sign in to comment.