File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -193,11 +193,18 @@ func choiceStructMapping(choice reflect.Type) (result map[string]structFieldInde
193
193
for i := 0 ; i < choice .NumField (); i ++ {
194
194
fieldType := choice .Field (i )
195
195
196
+ // Must be a pointer
196
197
if fieldType .Type .Kind () != reflect .Ptr {
197
198
continue
198
199
}
199
200
200
201
subtype := fieldType .Type .Elem ()
202
+
203
+ // Must be a pointer to struct
204
+ if subtype .Kind () != reflect .Struct {
205
+ continue
206
+ }
207
+
201
208
if t , err := jsonapiTypeOfModel (subtype ); err == nil {
202
209
result [t ] = structFieldIndex {
203
210
Type : subtype ,
Original file line number Diff line number Diff line change @@ -618,8 +618,10 @@ type Video struct {
618
618
}
619
619
620
620
type OneOfMedia struct {
621
- Image * Image
622
- Video * Video
621
+ Image * Image
622
+ random int
623
+ Video * Video
624
+ RandomStuff * string
623
625
}
624
626
625
627
func Test_UnmarshalPayload_polymorphicRelations (t * testing.T ) {
@@ -774,8 +776,8 @@ func Test_choiceStructMapping(t *testing.T) {
774
776
t .Errorf ("expected \" images\" to be the first field, but got %d" , imageField .FieldNum )
775
777
}
776
778
videoField , ok := result ["videos" ]
777
- if ! ok || videoField .FieldNum != 1 {
778
- t .Errorf ("expected \" videos\" to be the second field, but got %d" , videoField .FieldNum )
779
+ if ! ok || videoField .FieldNum != 2 {
780
+ t .Errorf ("expected \" videos\" to be the third field, but got %d" , videoField .FieldNum )
779
781
}
780
782
}
781
783
}
You can’t perform that action at this time.
0 commit comments