File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ type Company struct {
166
166
167
167
type Team struct {
168
168
Name string `jsonapi:"attr,name"`
169
- Leader * Employee `jsonapi:"attr,leader"`
169
+ Leader Employee `jsonapi:"attr,leader"`
170
170
Members []Employee `jsonapi:"attr,members"`
171
171
}
172
172
Original file line number Diff line number Diff line change @@ -902,6 +902,33 @@ func TestMarshal_InvalidIntefaceArgument(t *testing.T) {
902
902
}
903
903
}
904
904
905
+ func TestMarshalNestedStruct (t * testing.T ) {
906
+ team := Team {
907
+ Name : "Awesome team" ,
908
+ Leader : Employee {
909
+ Firstname : "John" ,
910
+ Surname : "Mota" ,
911
+ Age : 35 ,
912
+ },
913
+ Members : []Employee {
914
+ {
915
+ Firstname : "Henrique" ,
916
+ Surname : "Doe" ,
917
+ },
918
+ },
919
+ }
920
+
921
+ buffer := bytes .NewBuffer (nil )
922
+ MarshalOnePayloadEmbedded (buffer , & team )
923
+ reader := bytes .NewReader (buffer .Bytes ())
924
+ var finalTeam Team
925
+ UnmarshalPayload (reader , & finalTeam )
926
+
927
+ if ! reflect .DeepEqual (team , finalTeam ) {
928
+ t .Error ("final unmarshal payload should be equal to the original one." )
929
+ }
930
+ }
931
+
905
932
func testBlog () * Blog {
906
933
return & Blog {
907
934
ID : 5 ,
You can’t perform that action at this time.
0 commit comments