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 committed Jun 11, 2021
1 parent 33f2d5c commit 4a801ab
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions slices/map.go
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 4a801ab

Please sign in to comment.