From 44f66ae965c04ec00c87d9f1f0f10dca2c710c1f Mon Sep 17 00:00:00 2001 From: Michael Weibel Date: Tue, 9 May 2023 13:26:06 +0200 Subject: [PATCH] Revert "fix: empty map to empty json (#38)" This reverts commit 8d5788502af20b475d3bde855a1ce14f6d14897c. --- sheriff.go | 2 +- sheriff_test.go | 22 +--------------------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/sheriff.go b/sheriff.go index 332505c..8ce11db 100644 --- a/sheriff.go +++ b/sheriff.go @@ -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} diff --git a/sheriff_test.go b/sheriff_test.go index 6510824..d079e4b 100644 --- a/sheriff_test.go +++ b/sheriff_test.go @@ -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"` }