File tree 2 files changed +23
-4
lines changed
2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -149,10 +149,6 @@ func (c *checker) checkType(typ types.Type, tag string) bool {
149
149
}
150
150
c .seenTypes [typ .String ()] = struct {}{}
151
151
152
- if implementsInterface (typ , c .ifaceWhitelist , c .imports ) {
153
- return true // the type implements a Marshaler interface; see issue #64.
154
- }
155
-
156
152
styp , ok := c .parseStruct (typ )
157
153
if ! ok {
158
154
return true // not a struct.
@@ -161,7 +157,19 @@ func (c *checker) checkType(typ types.Type, tag string) bool {
161
157
return c .checkStruct (styp , tag )
162
158
}
163
159
160
+ // recursively unwrap a type until we get to an underlying
161
+ // raw struct type that should have its fields checked
162
+ //
163
+ // SomeStruct -> struct{SomeStructField: ... }
164
+ // []*SomeStruct -> struct{SomeStructField: ... }
165
+ // ...
166
+ //
167
+ // exits early if it hits a type that implements a whitelisted interface
164
168
func (c * checker ) parseStruct (typ types.Type ) (* types.Struct , bool ) {
169
+ if implementsInterface (typ , c .ifaceWhitelist , c .imports ) {
170
+ return nil , false // the type implements a Marshaler interface; see issue #64.
171
+ }
172
+
165
173
switch typ := typ .(type ) {
166
174
case * types.Pointer :
167
175
return c .parseStruct (typ .Elem ())
Original file line number Diff line number Diff line change @@ -164,3 +164,14 @@ func ignoredNestedType() {
164
164
json .Marshal (Foo {}) // no error
165
165
json .Marshal (& Foo {}) // no error
166
166
}
167
+
168
+ func interfaceSliceType () {
169
+ type WithMarshallableSlice struct {
170
+ List []Marshaler `json:"marshallable"`
171
+ }
172
+ var withMarshallableSlice WithMarshallableSlice
173
+
174
+ json .Marshal (withMarshallableSlice )
175
+ json .MarshalIndent (withMarshallableSlice , "" , "" )
176
+ json .NewEncoder (nil ).Encode (withMarshallableSlice )
177
+ }
You can’t perform that action at this time.
0 commit comments