Skip to content

Instantly share code, notes, and snippets.

@jonbodner
Created December 28, 2017 20:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonbodner/f8f7e4ecbbbfbad261868d808d00b02a to your computer and use it in GitHub Desktop.
Save jonbodner/f8f7e4ecbbbfbad261868d808d00b02a to your computer and use it in GitHub Desktop.
switch v.Kind() {
case reflect.Map:
// Map key must either have string kind, have an integer kind,
// or be an encoding.TextUnmarshaler.
t := v.Type()
switch t.Key().Kind() {
case reflect.String,
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
default:
if !reflect.PtrTo(t.Key()).Implements(textUnmarshalerType) {
d.saveError(&UnmarshalTypeError{Value: "object", Type: v.Type(), Offset: int64(d.off)})
d.off --
d.next() // skip over { } in input
return
}
}
if v.IsNil() {
v.Set(reflect.MakeMap(t))
}
case reflect.Struct:
// ok
default:
d.saveError(&UnmarshalTypeError{Value: "object", Type: v.Type(), Offset: int64(d.off)})
d.off --
d.next() // skip over { } in input
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment