diff options
Diffstat (limited to 'src/encoding')
| -rw-r--r-- | src/encoding/xml/marshal_test.go | 10 | ||||
| -rw-r--r-- | src/encoding/xml/typeinfo.go | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/encoding/xml/marshal_test.go b/src/encoding/xml/marshal_test.go index 330fbee1af..aab94b16f3 100644 --- a/src/encoding/xml/marshal_test.go +++ b/src/encoding/xml/marshal_test.go @@ -139,6 +139,7 @@ type EmbedA struct { EmbedC EmbedB EmbedB FieldA string + embedD } type EmbedB struct { @@ -153,6 +154,11 @@ type EmbedC struct { FieldC string } +type embedD struct { + fieldD string + FieldE string // Promoted and visible when embedD is embedded. +} + type NameCasing struct { XMLName struct{} `xml:"casing"` Xy string @@ -711,6 +717,9 @@ var marshalTests = []struct { }, }, FieldA: "A.A", + embedD: embedD{ + FieldE: "A.D.E", + }, }, ExpectXML: `<EmbedA>` + `<FieldB>A.C.B</FieldB>` + @@ -724,6 +733,7 @@ var marshalTests = []struct { `<FieldC>A.B.C.C</FieldC>` + `</EmbedB>` + `<FieldA>A.A</FieldA>` + + `<FieldE>A.D.E</FieldE>` + `</EmbedA>`, }, diff --git a/src/encoding/xml/typeinfo.go b/src/encoding/xml/typeinfo.go index 22248d20a6..6766b88f09 100644 --- a/src/encoding/xml/typeinfo.go +++ b/src/encoding/xml/typeinfo.go @@ -60,7 +60,7 @@ func getTypeInfo(typ reflect.Type) (*typeInfo, error) { n := typ.NumField() for i := 0; i < n; i++ { f := typ.Field(i) - if f.PkgPath != "" || f.Tag.Get("xml") == "-" { + if (f.PkgPath != "" && !f.Anonymous) || f.Tag.Get("xml") == "-" { continue // Private field } |
