@@ -193,7 +193,10 @@ func MarshalOnePayloadEmbedded(w io.Writer, model interface{}) error {
193
193
return json .NewEncoder (w ).Encode (payload )
194
194
}
195
195
196
- func chooseFirstNonNilFieldValue (structValue reflect.Value ) (reflect.Value , error ) {
196
+ // selectChoiceTypeStructField returns the first non-nil struct pointer field in the
197
+ // specified struct value that has a jsonapi type field defined within it.
198
+ // An error is returned if there are no fields matching that definition.
199
+ func selectChoiceTypeStructField (structValue reflect.Value ) (reflect.Value , error ) {
197
200
for i := 0 ; i < structValue .NumField (); i ++ {
198
201
choiceFieldValue := structValue .Field (i )
199
202
choiceTypeField := choiceFieldValue .Type ()
@@ -416,7 +419,7 @@ func visitModelNode(model interface{}, included *map[string]*Node,
416
419
}
417
420
418
421
structValue := choiceValue .Elem ()
419
- if found , err := chooseFirstNonNilFieldValue (structValue ); err == nil {
422
+ if found , err := selectChoiceTypeStructField (structValue ); err == nil {
420
423
fieldValue = found
421
424
}
422
425
} else {
@@ -442,7 +445,7 @@ func visitModelNode(model interface{}, included *map[string]*Node,
442
445
443
446
structValue := itemValue .Elem ()
444
447
445
- if found , err := chooseFirstNonNilFieldValue (structValue ); err == nil {
448
+ if found , err := selectChoiceTypeStructField (structValue ); err == nil {
446
449
collection = append (collection , found .Interface ())
447
450
}
448
451
}
0 commit comments