@@ -140,7 +140,6 @@ func UnmarshalManyPayload(in io.Reader, t reflect.Type) ([]interface{}, error) {
140
140
}
141
141
142
142
func unmarshalNode (data * Node , model reflect.Value , included * map [string ]* Node ) (err error ) {
143
-
144
143
defer func () {
145
144
if r := recover (); r != nil {
146
145
err = fmt .Errorf ("data is not a jsonapi representation of '%v'" , model .Type ())
@@ -386,8 +385,11 @@ func assign(field, value reflect.Value) {
386
385
}
387
386
}
388
387
389
- func unmarshalAttribute (attribute interface {}, args []string , structField reflect.StructField , fieldValue reflect.Value ) (value reflect.Value , err error ) {
390
-
388
+ func unmarshalAttribute (
389
+ attribute interface {},
390
+ args []string ,
391
+ structField reflect.StructField ,
392
+ fieldValue reflect.Value ) (value reflect.Value , err error ) {
391
393
value = reflect .ValueOf (attribute )
392
394
fieldType := structField .Type
393
395
@@ -398,7 +400,8 @@ func unmarshalAttribute(attribute interface{}, args []string, structField reflec
398
400
}
399
401
400
402
// Handle field of type time.Time
401
- if fieldValue .Type () == reflect .TypeOf (time.Time {}) || fieldValue .Type () == reflect .TypeOf (new (time.Time )) {
403
+ if fieldValue .Type () == reflect .TypeOf (time.Time {}) ||
404
+ fieldValue .Type () == reflect .TypeOf (new (time.Time )) {
402
405
value , err = handleTime (attribute , args , fieldType , fieldValue )
403
406
return
404
407
}
@@ -410,7 +413,8 @@ func unmarshalAttribute(attribute interface{}, args []string, structField reflec
410
413
}
411
414
412
415
// Handle field containing slice of structs
413
- if fieldValue .Type ().Kind () == reflect .Slice && reflect .TypeOf (fieldValue .Interface ()).Elem ().Kind () == reflect .Struct {
416
+ if fieldValue .Type ().Kind () == reflect .Slice &&
417
+ reflect .TypeOf (fieldValue .Interface ()).Elem ().Kind () == reflect .Struct {
414
418
value , err = handleStructSlice (attribute , args , fieldType , fieldValue )
415
419
return
416
420
}
@@ -436,7 +440,11 @@ func unmarshalAttribute(attribute interface{}, args []string, structField reflec
436
440
return
437
441
}
438
442
439
- func handleStringSlice (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
443
+ func handleStringSlice (
444
+ attribute interface {},
445
+ args []string ,
446
+ fieldType reflect.Type ,
447
+ fieldValue reflect.Value ) (reflect.Value , error ) {
440
448
v := reflect .ValueOf (attribute )
441
449
values := make ([]string , v .Len ())
442
450
for i := 0 ; i < v .Len (); i ++ {
@@ -446,8 +454,11 @@ func handleStringSlice(attribute interface{}, args []string, fieldType reflect.T
446
454
return reflect .ValueOf (values ), nil
447
455
}
448
456
449
- func handleTime (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
450
-
457
+ func handleTime (
458
+ attribute interface {},
459
+ args []string ,
460
+ fieldType reflect.Type ,
461
+ fieldValue reflect.Value ) (reflect.Value , error ) {
451
462
var isIso8601 bool
452
463
v := reflect .ValueOf (attribute )
453
464
@@ -494,7 +505,11 @@ func handleTime(attribute interface{}, args []string, fieldType reflect.Type, fi
494
505
return reflect .ValueOf (t ), nil
495
506
}
496
507
497
- func handleNumeric (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
508
+ func handleNumeric (
509
+ attribute interface {},
510
+ args []string ,
511
+ fieldType reflect.Type ,
512
+ fieldValue reflect.Value ) (reflect.Value , error ) {
498
513
v := reflect .ValueOf (attribute )
499
514
floatValue := v .Interface ().(float64 )
500
515
@@ -551,7 +566,12 @@ func handleNumeric(attribute interface{}, args []string, fieldType reflect.Type,
551
566
return numericValue , nil
552
567
}
553
568
554
- func handlePointer (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value , structField reflect.StructField ) (reflect.Value , error ) {
569
+ func handlePointer (
570
+ attribute interface {},
571
+ args []string ,
572
+ fieldType reflect.Type ,
573
+ fieldValue reflect.Value ,
574
+ structField reflect.StructField ) (reflect.Value , error ) {
555
575
t := fieldValue .Type ()
556
576
var concreteVal reflect.Value
557
577
@@ -560,50 +580,55 @@ func handlePointer(attribute interface{}, args []string, fieldType reflect.Type,
560
580
concreteVal = reflect .ValueOf (& cVal )
561
581
case bool :
562
582
concreteVal = reflect .ValueOf (& cVal )
563
- case complex64 :
564
- concreteVal = reflect .ValueOf (& cVal )
565
- case complex128 :
566
- concreteVal = reflect .ValueOf (& cVal )
567
- case uintptr :
583
+ case complex64 , complex128 , uintptr :
568
584
concreteVal = reflect .ValueOf (& cVal )
569
585
case map [string ]interface {}:
570
586
var err error
571
587
concreteVal , err = handleStruct (attribute , args , fieldType , fieldValue )
572
588
if err != nil {
573
- return reflect.Value {}, newErrUnsupportedPtrType (reflect .ValueOf (attribute ), fieldType , structField )
589
+ return reflect.Value {}, newErrUnsupportedPtrType (
590
+ reflect .ValueOf (attribute ), fieldType , structField )
574
591
}
575
592
return concreteVal .Elem (), err
576
593
default :
577
- return reflect.Value {}, newErrUnsupportedPtrType (reflect .ValueOf (attribute ), fieldType , structField )
594
+ return reflect.Value {}, newErrUnsupportedPtrType (
595
+ reflect .ValueOf (attribute ), fieldType , structField )
578
596
}
579
597
580
598
if t != concreteVal .Type () {
581
- return reflect.Value {}, newErrUnsupportedPtrType (reflect .ValueOf (attribute ), fieldType , structField )
599
+ return reflect.Value {}, newErrUnsupportedPtrType (
600
+ reflect .ValueOf (attribute ), fieldType , structField )
582
601
}
583
602
584
603
return concreteVal , nil
585
604
}
586
605
587
- func handleStruct (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
606
+ func handleStruct (
607
+ attribute interface {},
608
+ args []string ,
609
+ fieldType reflect.Type ,
610
+ fieldValue reflect.Value ) (reflect.Value , error ) {
588
611
model := reflect .New (fieldValue .Type ())
589
612
590
- var er error
591
-
592
- data , er := json .Marshal (attribute )
593
- if er != nil {
594
- return model , er
613
+ data , err := json .Marshal (attribute )
614
+ if err != nil {
615
+ return model , err
595
616
}
596
617
597
- er = json .Unmarshal (data , model .Interface ())
618
+ err = json .Unmarshal (data , model .Interface ())
598
619
599
- if er != nil {
600
- return model , er
620
+ if err != nil {
621
+ return model , err
601
622
}
602
623
603
- return model , er
624
+ return model , err
604
625
}
605
626
606
- func handleStructSlice (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
627
+ func handleStructSlice (
628
+ attribute interface {},
629
+ args []string ,
630
+ fieldType reflect.Type ,
631
+ fieldValue reflect.Value ) (reflect.Value , error ) {
607
632
models := reflect .New (fieldValue .Type ()).Elem ()
608
633
dataMap := reflect .ValueOf (attribute ).Interface ().([]interface {})
609
634
for _ , data := range dataMap {
0 commit comments