mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
23fab11c47
commit
3be088e354
4 changed files with 42 additions and 26 deletions
|
|
@ -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}},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue