@@ -26,6 +26,7 @@ type TestGroupsModel struct {
26
26
OmitEmptyGroupTest string `json:"omit_empty_group_test,omitempty" groups:"test"`
27
27
SliceString []string `json:"slice_string,omitempty" groups:"test"`
28
28
MapStringStruct map [string ]AModel `json:"map_string_struct,omitempty" groups:"test,test-other"`
29
+ IncludeEmptyTag string `json:"include_empty_tag"`
29
30
}
30
31
31
32
func TestMarshal_GroupsValidGroup (t * testing.T ) {
@@ -141,6 +142,7 @@ func TestMarshal_GroupsNoGroups(t *testing.T) {
141
142
GroupTestAndOther : "GroupTestAndOther" ,
142
143
OmitEmpty : "OmitEmpty" ,
143
144
OmitEmptyGroupTest : "OmitEmptyGroupTest" ,
145
+ IncludeEmptyTag : "IncludeEmptyTag" ,
144
146
MapStringStruct : map [string ]AModel {"firstModel" : {true , true }},
145
147
}
146
148
@@ -165,6 +167,42 @@ func TestMarshal_GroupsNoGroups(t *testing.T) {
165
167
},
166
168
"omit_empty" : "OmitEmpty" ,
167
169
"omit_empty_group_test" : "OmitEmptyGroupTest" ,
170
+ "include_empty_tag" : "IncludeEmptyTag" ,
171
+ })
172
+ assert .NoError (t , err )
173
+
174
+ assert .Equal (t , string (expected ), string (actual ))
175
+ }
176
+
177
+ func TestMarshal_GroupsValidGroupIncludeEmptyTag (t * testing.T ) {
178
+ testModel := & TestGroupsModel {
179
+ DefaultMarshal : "DefaultMarshal" ,
180
+ OnlyGroupTest : "OnlyGroupTest" ,
181
+ GroupTestAndOther : "GroupTestAndOther" ,
182
+ OmitEmpty : "OmitEmpty" ,
183
+ OmitEmptyGroupTest : "" ,
184
+ SliceString : []string {"test" , "bla" },
185
+ IncludeEmptyTag : "IncludeEmptyTag" ,
186
+ }
187
+
188
+ o := & Options {
189
+ IncludeEmptyTag : true ,
190
+ Groups : []string {"test" },
191
+ }
192
+
193
+ actualMap , err := Marshal (o , testModel )
194
+ assert .NoError (t , err )
195
+
196
+ actual , err := json .Marshal (actualMap )
197
+ assert .NoError (t , err )
198
+
199
+ expected , err := json .Marshal (map [string ]interface {}{
200
+ "default_marshal" : "DefaultMarshal" ,
201
+ "only_group_test" : "OnlyGroupTest" ,
202
+ "group_test_and_other" : "GroupTestAndOther" ,
203
+ "omit_empty" : "OmitEmpty" ,
204
+ "slice_string" : []string {"test" , "bla" },
205
+ "include_empty_tag" : "IncludeEmptyTag" ,
168
206
})
169
207
assert .NoError (t , err )
170
208
0 commit comments