-
-
Save vanleantking/bf4c2203f927ee08bf47ab9b48a68921 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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