Skip to content

Commit

Permalink
Revert "fix: empty map to empty json (#38)"
Browse files Browse the repository at this point in the history
This reverts commit 8d57885.
  • Loading branch information
mweibel committed May 9, 2023
1 parent 798c3d1 commit 44f66ae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
2 changes: 1 addition & 1 deletion sheriff.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func marshalValue(options *Options, v reflect.Value) (interface{}, error) {
if k == reflect.Map {
mapKeys := v.MapKeys()
if len(mapKeys) == 0 {
return val, nil
return nil, nil
}
if mapKeys[0].Kind() != reflect.String {
return nil, MarshalInvalidTypeError{t: mapKeys[0].Kind(), data: val}
Expand Down
22 changes: 1 addition & 21 deletions sheriff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,33 +505,13 @@ func TestMarshal_EmptyMap(t *testing.T) {
assert.NoError(t, err)

expected, err := json.Marshal(map[string]interface{}{
"a_map": make(map[string]interface{}),
"a_map": nil,
})
assert.NoError(t, err)

assert.Equal(t, string(expected), string(actual))
}

func TestMarshal_EmptyMapJson(t *testing.T) {
emp := EmptyMapTest{
AMap: make(map[string]string),
}
o := &Options{
Groups: []string{"test"},
}

actualMap, err := Marshal(o, emp)
assert.NoError(t, err)

actual, err := json.Marshal(actualMap)
assert.NoError(t, err)

expected, err := json.Marshal(emp)
assert.NoError(t, err)

assert.Equal(t, string(expected), string(actual))
}

type TestMarshal_Embedded struct {
Foo string `json:"foo" groups:"test"`
}
Expand Down

0 comments on commit 44f66ae

Please sign in to comment.