We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 44f66ae commit fc115baCopy full SHA for fc115ba
sheriff.go
@@ -56,7 +56,7 @@ type Marshaller interface {
56
// In all other cases we can't derive the type in a meaningful way and is therefore an `interface{}`.
57
func Marshal(options *Options, data interface{}) (interface{}, error) {
58
v := reflect.ValueOf(data)
59
- if !v.IsValid() {
+ if !v.IsValid() || v.Kind() == reflect.Ptr && v.IsNil() {
60
return data, nil
61
}
62
t := v.Type()
sheriff_test.go
@@ -747,3 +747,10 @@ func TestMarshal_NilSlice(t *testing.T) {
747
748
assert.Equal(t, expect, string(jsonResult))
749
750
+
751
+func TestMarshal_NilPointer(t *testing.T) {
752
+ var a *AModel
753
+ v, err := Marshal(&Options{}, a)
754
+ assert.Nil(t, v)
755
+ assert.NoError(t, err)
756
+}
0 commit comments