Skip to content

Commit

Permalink
Make slices.Map UnmarshalJSON a pointer receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
naemono authored and sio4 committed Sep 18, 2022
1 parent f192ebb commit 32ad898
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions slices/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ func (m Map) Value() (driver.Value, error) {

// UnmarshalJSON will unmarshall JSON value into
// the map representation of this value.
func (m Map) UnmarshalJSON(b []byte) error {
func (m *Map) UnmarshalJSON(b []byte) error {
var stuff map[string]interface{}
err := json.Unmarshal(b, &stuff)
if err != nil {
return err
}
if m == nil {
m = Map{}
if *m == nil {
*m = Map{}
}
for key, value := range stuff {
m[key] = value
(*m)[key] = value
}
return nil
}
Expand Down

0 comments on commit 32ad898

Please sign in to comment.