Skip to content

Commit

Permalink
Merge branch 'master' into bugfix_issue37_empty_map_nil
Browse files Browse the repository at this point in the history
  • Loading branch information
mweibel authored May 9, 2023
2 parents 87e191f + ecc6ca1 commit 062fe8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sheriff.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func marshalValue(options *Options, v reflect.Value) (interface{}, error) {
k := v.Kind()

switch k {
case reflect.Interface, reflect.Map, reflect.Ptr:
case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
if v.IsNil() {
return val, nil
}
Expand Down
14 changes: 14 additions & 0 deletions sheriff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,20 @@ func TestMarshal_NilSlice(t *testing.T) {
jsonResult, err := json.Marshal(marshalSlice)
assert.NoError(t, err)

expect := "null"

assert.Equal(t, expect, string(jsonResult))
}

func TestMarshal_EmptySlice(t *testing.T) {
var stringSlice = []string{} // empty slice

marshalSlice, err := Marshal(&Options{}, stringSlice)
assert.NoError(t, err)

jsonResult, err := json.Marshal(marshalSlice)
assert.NoError(t, err)

expect := "[]"

assert.Equal(t, expect, string(jsonResult))
Expand Down

0 comments on commit 062fe8d

Please sign in to comment.