@@ -694,6 +694,14 @@ func TestMarshalObjectAttribute(t *testing.T) {
694
694
Firstname : "Dave" ,
695
695
HiredAt : & now ,
696
696
},
697
+ Teams : []Team {
698
+ {Name : "Team 1" },
699
+ {Name : "Team-2" },
700
+ },
701
+ People : []* People {
702
+ {Name : "Person-1" },
703
+ {Name : "Person-2" },
704
+ },
697
705
}
698
706
699
707
out := bytes .NewBuffer (nil )
@@ -734,6 +742,69 @@ func TestMarshalObjectAttribute(t *testing.T) {
734
742
if manager ["firstname" ] != "Dave" {
735
743
t .Fatalf ("Expected manager.firstname to be \" Dave\" , got %v" , manager )
736
744
}
745
+
746
+ people , ok := data .Attributes ["people" ].([]interface {})
747
+ if ! ok {
748
+ t .Fatalf ("Expected people attribute, got %v" , data .Attributes )
749
+ }
750
+ if len (people ) != 2 {
751
+ t .Fatalf ("Expected 2 people, got %v" , people )
752
+ }
753
+
754
+ teams , ok := data .Attributes ["teams" ].([]interface {})
755
+ if ! ok {
756
+ t .Fatalf ("Expected teams attribute, got %v" , data .Attributes )
757
+ }
758
+ if len (teams ) != 2 {
759
+ t .Fatalf ("Expected 2 teams, got %v" , teams )
760
+ }
761
+ }
762
+
763
+ func TestMarshalObjectAttributeWithEmptyNested (t * testing.T ) {
764
+ testModel := & CompanyOmitEmpty {
765
+ ID : "5" ,
766
+ Name : "test" ,
767
+ Boss : Employee {},
768
+ Manager : nil ,
769
+ Teams : []Team {},
770
+ People : nil ,
771
+ }
772
+
773
+ out := bytes .NewBuffer (nil )
774
+ if err := MarshalPayload (out , testModel ); err != nil {
775
+ t .Fatal (err )
776
+ }
777
+
778
+ resp := new (OnePayload )
779
+ if err := json .NewDecoder (out ).Decode (resp ); err != nil {
780
+ t .Fatal (err )
781
+ }
782
+
783
+ data := resp .Data
784
+
785
+ if data .Attributes == nil {
786
+ t .Fatalf ("Expected attributes" )
787
+ }
788
+
789
+ _ , ok := data .Attributes ["boss" ].(map [string ]interface {})
790
+ if ok {
791
+ t .Fatalf ("Expected omitted boss attribute, got %v" , data .Attributes )
792
+ }
793
+
794
+ _ , ok = data .Attributes ["manager" ].(map [string ]interface {})
795
+ if ok {
796
+ t .Fatalf ("Expected omitted manager attribute, got %v" , data .Attributes )
797
+ }
798
+
799
+ _ , ok = data .Attributes ["people" ].([]interface {})
800
+ if ok {
801
+ t .Fatalf ("Expected omitted people attribute, got %v" , data .Attributes )
802
+ }
803
+
804
+ _ , ok = data .Attributes ["teams" ].([]interface {})
805
+ if ok {
806
+ t .Fatalf ("Expected omitted teams attribute, got %v" , data .Attributes )
807
+ }
737
808
}
738
809
739
810
func TestOmitsZeroTimes (t * testing.T ) {
0 commit comments