From 15804f7fdfd92c57c76daedb2ab2ae7dda0c0c28 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 25 Nov 2020 12:23:38 +0300 Subject: [PATCH] add nil check Signed-off-by: Vasiliy Tolstov --- jsonpb.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jsonpb.go b/jsonpb.go index 056fbf2..afa671c 100644 --- a/jsonpb.go +++ b/jsonpb.go @@ -39,6 +39,9 @@ var ( type jsonpbCodec struct{} func (c *jsonpbCodec) Marshal(v interface{}) ([]byte, error) { + if v == nil { + return nil, nil + } switch m := v.(type) { case *codec.Frame: return m.Data, nil @@ -52,7 +55,7 @@ func (c *jsonpbCodec) Marshal(v interface{}) ([]byte, error) { } func (c *jsonpbCodec) Unmarshal(d []byte, v interface{}) error { - if d == nil { + if d == nil || v == nil { return nil } switch m := v.(type) {