File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ type Marshaller interface {
56
56
// In all other cases we can't derive the type in a meaningful way and is therefore an `interface{}`.
57
57
func Marshal (options * Options , data interface {}) (interface {}, error ) {
58
58
v := reflect .ValueOf (data )
59
- if ! v .IsValid () {
59
+ if ! v .IsValid () || v . Kind () == reflect . Ptr && v . IsNil () {
60
60
return data , nil
61
61
}
62
62
t := v .Type ()
Original file line number Diff line number Diff line change @@ -747,3 +747,10 @@ func TestMarshal_NilSlice(t *testing.T) {
747
747
748
748
assert .Equal (t , expect , string (jsonResult ))
749
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
+ }
You can’t perform that action at this time.
0 commit comments