diff --git a/internal/modifiers/json_modifier.go b/internal/modifiers/json_modifier.go index 7e5cb61..f408c5f 100644 --- a/internal/modifiers/json_modifier.go +++ b/internal/modifiers/json_modifier.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "reflect" ) // This modifier serializes objects as JSON when @@ -13,10 +12,6 @@ import ( var jsonModifier = AttrModifier{ Scan: func(ctx context.Context, opInfo OpInfo, attrPtr interface{}, dbValue interface{}) error { if dbValue == nil { - v := reflect.ValueOf(attrPtr) - // Set the struct to its 0 value just like json.Unmarshal - // does for nil attributes: - v.Elem().Set(reflect.Zero(reflect.TypeOf(attrPtr).Elem())) return nil } diff --git a/internal/modifiers/json_modifier_test.go b/internal/modifiers/json_modifier_test.go index 335356e..a53f56c 100644 --- a/internal/modifiers/json_modifier_test.go +++ b/internal/modifiers/json_modifier_test.go @@ -21,9 +21,11 @@ func TestAttrScan(t *testing.T) { expectErrToContain []string }{ { - desc: "should set struct to zero value if input is nil", - dbInput: nil, - expectedValue: FakeAttr{}, + desc: "should not set struct to zero value if input is nil", + dbInput: nil, + expectedValue: FakeAttr{ + Foo: "notZeroValue", + }, }, { desc: "should work when input is a byte slice",