Skip to content

Commit

Permalink
Force string-typed keys
Browse files Browse the repository at this point in the history
When unmarshaling objects to map[string]interface{}, map values will be
of the type map[interface{}]interface{}. This is problematic when
attempting to marshal the object out to JSON, since encoding/json only
supports string keys.

This change is a patch to cause all child maps to have string-typed
keys.
  • Loading branch information
Jordan Olshevski committed Jul 13, 2016
1 parent a83829b commit 85482c8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ type decoder struct {
var (
mapItemType = reflect.TypeOf(MapItem{})
durationType = reflect.TypeOf(time.Duration(0))
defaultMapType = reflect.TypeOf(map[interface{}]interface{}{})
defaultMapType = reflect.TypeOf(map[string]interface{}{})
ifaceType = defaultMapType.Elem()
)

Expand Down

1 comment on commit 85482c8

@ashald
Copy link

@ashald ashald commented on 85482c8 May 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to say thanks for this as I cherry-picked it into my fork ashald@20b2b74 😊

Please sign in to comment.