json: if a field's tag is "-", never encode it.

R=adg, r, edsrzf, rsc, r
CC=golang-dev
https://golang.org/cl/4962052
This commit is contained in:
David Symonds 2011-09-15 08:09:43 +10:00
parent 23fab11c47
commit 3be088e354
4 changed files with 42 additions and 26 deletions

View file

@ -15,6 +15,7 @@ import (
type T struct {
X string
Y int
Z int `json:"-"`
}
type tx struct {
@ -68,6 +69,9 @@ var unmarshalTests = []unmarshalTest{
{`{"X": [1,2,3], "Y": 4}`, new(T), T{Y: 4}, &UnmarshalTypeError{"array", reflect.TypeOf("")}},
{`{"x": 1}`, new(tx), tx{}, &UnmarshalFieldError{"x", txType, txType.Field(0)}},
// Z has a "-" tag.
{`{"Y": 1, "Z": 2}`, new(T), T{Y: 1}, nil},
// syntax errors
{`{"X": "foo", "Y"}`, nil, nil, &SyntaxError{"invalid character '}' after object key", 17}},