Skip to content

Commit 44f66ae

Browse files
committed
Revert "fix: empty map to empty json (#38)"
This reverts commit 8d57885.
1 parent 798c3d1 commit 44f66ae

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed

sheriff.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func marshalValue(options *Options, v reflect.Value) (interface{}, error) {
248248
if k == reflect.Map {
249249
mapKeys := v.MapKeys()
250250
if len(mapKeys) == 0 {
251-
return val, nil
251+
return nil, nil
252252
}
253253
if mapKeys[0].Kind() != reflect.String {
254254
return nil, MarshalInvalidTypeError{t: mapKeys[0].Kind(), data: val}

sheriff_test.go

+1-21
Original file line numberDiff line numberDiff line change
@@ -505,33 +505,13 @@ func TestMarshal_EmptyMap(t *testing.T) {
505505
assert.NoError(t, err)
506506

507507
expected, err := json.Marshal(map[string]interface{}{
508-
"a_map": make(map[string]interface{}),
508+
"a_map": nil,
509509
})
510510
assert.NoError(t, err)
511511

512512
assert.Equal(t, string(expected), string(actual))
513513
}
514514

515-
func TestMarshal_EmptyMapJson(t *testing.T) {
516-
emp := EmptyMapTest{
517-
AMap: make(map[string]string),
518-
}
519-
o := &Options{
520-
Groups: []string{"test"},
521-
}
522-
523-
actualMap, err := Marshal(o, emp)
524-
assert.NoError(t, err)
525-
526-
actual, err := json.Marshal(actualMap)
527-
assert.NoError(t, err)
528-
529-
expected, err := json.Marshal(emp)
530-
assert.NoError(t, err)
531-
532-
assert.Equal(t, string(expected), string(actual))
533-
}
534-
535515
type TestMarshal_Embedded struct {
536516
Foo string `json:"foo" groups:"test"`
537517
}

0 commit comments

Comments
 (0)