@@ -385,12 +385,6 @@ func unmarshalAttribute(attribute interface{}, args []string, fieldType reflect.
385
385
return
386
386
}
387
387
388
- // Handle field of type struct
389
- if fieldValue .Type ().Kind () == reflect .Struct {
390
- value , err = handleStruct (attribute , args , fieldType , fieldValue )
391
- return
392
- }
393
-
394
388
// Handle field containing slice of structs
395
389
if fieldValue .Type ().Kind () == reflect .Slice && reflect .TypeOf (fieldValue .Interface ()).Elem ().Kind () == reflect .Struct {
396
390
value , err = handleStructSlice (attribute , args , fieldType , fieldValue )
@@ -562,44 +556,17 @@ func handlePointer(attribute interface{}, args []string, fieldType reflect.Type,
562
556
func handleStruct (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
563
557
model := reflect .New (fieldValue .Type ())
564
558
565
- modelValue := model .Elem ()
566
- modelType := model .Type ().Elem ()
567
-
568
559
var er error
569
560
570
- for i := 0 ; i < modelValue .NumField (); i ++ {
571
- fieldType := modelType .Field (i )
572
- tag := fieldType .Tag .Get ("jsonapi" )
573
- if tag == "" {
574
- continue
575
- }
576
-
577
- fieldValue := modelValue .Field (i )
578
-
579
- args := strings .Split (tag , "," )
580
-
581
- if len (args ) < 1 {
582
- er = ErrBadJSONAPIStructTag
583
- break
584
- }
585
-
586
- if reflect .TypeOf (attribute ).Kind () != reflect .Map {
587
- return model , nil
588
- }
589
-
590
- attributes := reflect .ValueOf (attribute ).Interface ().(map [string ]interface {})
591
- attribute := attributes [args [1 ]]
592
-
593
- if attribute == nil {
594
- continue
595
- }
561
+ data , er := json .Marshal (attribute )
562
+ if er != nil {
563
+ return model , er
564
+ }
596
565
597
- value , err := unmarshalAttribute (attribute , args , fieldType .Type , fieldValue )
598
- if err != nil {
599
- return model , nil
600
- }
566
+ er = json .Unmarshal (data , model .Interface ())
601
567
602
- assign (fieldValue , value )
568
+ if er != nil {
569
+ return model , er
603
570
}
604
571
605
572
return model , er
0 commit comments