json: unmarshal types that are byte slices.

The json package cheerfully would marshal

        type S struct {
                IP net.IP
        }

but would give an error when unmarshalling.  This change allows any
type whose concrete type is a byte slice to be unmarshalled from a
string.

Fixes #5086.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/11161044
This commit is contained in:
Paul Borman 2013-07-11 22:34:09 -04:00 committed by Russ Cox
parent 09e72f5670
commit 5930649306
3 changed files with 32 additions and 3 deletions

View file

@ -660,7 +660,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
default:
d.saveError(&UnmarshalTypeError{"string", v.Type()})
case reflect.Slice:
if v.Type() != byteSliceType {
if v.Type().Elem().Kind() != reflect.Uint8 {
d.saveError(&UnmarshalTypeError{"string", v.Type()})
break
}