File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ func (t JSON) String() string {
4141 if t .Omitempty {
4242 tag += ",omitempty"
4343 }
44+ // "inline" isn't (yet) a standard json tag, but it is used by
45+ // gengo to indicate that the field should be inlined.
4446 if t .Inline {
4547 tag += ",inline"
4648 }
@@ -53,7 +55,9 @@ func LookupJSON(m types.Member) (JSON, bool) {
5355 return JSON {Omit : true }, true
5456 }
5557 name , opts := parse (tag )
56- inline := opts .Contains ("inline" )
58+ // "inline" isn't (yet) a standard json tag, but it is used by
59+ // gengo to indicate that the field should be inlined.
60+ inline := (m .Embedded && name == "" ) || opts .Contains ("inline" )
5761 omitempty := opts .Contains ("omitempty" )
5862 if ! inline && name == "" {
5963 name = m .Name
Original file line number Diff line number Diff line change @@ -73,6 +73,16 @@ func TestJSON(t *testing.T) {
7373 member : member ("T1" , "E" ),
7474 expected : JSON {Name : "E" },
7575 },
76+ {
77+ name : "embedded struct" ,
78+ member : member ("T1" , "T2" ),
79+ expected : JSON {Name : "" , Inline : true },
80+ },
81+ {
82+ name : "embedded pointer" ,
83+ member : member ("T1" , "T3" ),
84+ expected : JSON {Name : "" , Inline : true },
85+ },
7686 }
7787
7888 for _ , tt := range tests {
Original file line number Diff line number Diff line change @@ -6,4 +6,15 @@ type T1 struct {
66 C string `json:",inline"`
77 D string `json:"-"`
88 E string `json:""`
9+
10+ T2
11+ * T3
12+ }
13+
14+ type T2 struct {
15+ Z string `json:"z"`
16+ }
17+
18+ type T3 struct {
19+ Y string `json:"y"`
920}
You can’t perform that action at this time.
0 commit comments