undo CL 11161044 / ba455262a9db

I want to think more carefully about this.

We put this in because Marshal encoded named []byte but Unmarshal rejected them.
And we noticed that Marshal's behavior was undocumented so we documented it.
But I am starting to think the docs and Unmarshal were correct and Marshal's
behavior was the problem.

Rolling back to give us more time to think.

««« original CL description
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

»»»

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/11042046
This commit is contained in:
Russ Cox 2013-07-12 17:42:01 -04:00
parent 64054a40ad
commit 4419d7e53c
3 changed files with 3 additions and 32 deletions

View file

@ -1186,32 +1186,3 @@ func TestSkipArrayObjects(t *testing.T) {
t.Errorf("got error %q, want nil", err)
}
}
// Test that types of byte slices (such as net.IP) both
// marshal and unmarshal.
func TestByteSliceType(t *testing.T) {
type A []byte
type S struct {
A A
}
for x, in := range []S{
S{},
S{A: []byte{'1'}},
S{A: []byte{'1', '2', '3', '4', '5'}},
} {
data, err := Marshal(&in)
if err != nil {
t.Errorf("#%d: got Marshal error %q, want nil", x, err)
continue
}
var out S
err = Unmarshal(data, &out)
if err != nil {
t.Fatalf("#%d: got Unmarshal error %q, want nil", x, err)
}
if !reflect.DeepEqual(&out, &in) {
t.Fatalf("#%d: got %v, want %v", x, &out, &in)
}
}
}