Skip to content

Instantly share code, notes, and snippets.

@vanleantking
Forked from jonbodner/reflection2_3.go
Created June 26, 2019 09:50
Show Gist options
  • Save vanleantking/bf4c2203f927ee08bf47ab9b48a68921 to your computer and use it in GitHub Desktop.
Save vanleantking/bf4c2203f927ee08bf47ab9b48a68921 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