mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: disable anonymous fields
We should, after Go 1, make them work the same as package xml, that is, make them appear in the outer struct. For now turn them off so that people do not depend on the old behavior. Fixing them is issue 3069. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5656102
This commit is contained in:
parent
89b075cc90
commit
990f9f4c00
3 changed files with 48 additions and 0 deletions
|
|
@ -496,6 +496,12 @@ func (d *decodeState) object(v reflect.Value) {
|
|||
// Pretend this field doesn't exist.
|
||||
continue
|
||||
}
|
||||
if sf.Anonymous {
|
||||
// Pretend this field doesn't exist,
|
||||
// so that we can do a good job with
|
||||
// these in a later version.
|
||||
continue
|
||||
}
|
||||
// First, tag match
|
||||
tagName, _ := parseTag(tag)
|
||||
if tagName == key {
|
||||
|
|
@ -963,3 +969,11 @@ func unquoteBytes(s []byte) (t []byte, ok bool) {
|
|||
}
|
||||
return b[0:w], true
|
||||
}
|
||||
|
||||
// The following is issue 3069.
|
||||
|
||||
// BUG(rsc): This package ignores anonymous (embedded) struct fields
|
||||
// during encoding and decoding. A future version may assign meaning
|
||||
// to them. To force an anonymous field to be ignored in all future
|
||||
// versions of this package, use an explicit `json:"-"` tag in the struct
|
||||
// definition.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue