diff --git a/list.go b/list.go index c89bc49d..0ce242b8 100644 --- a/list.go +++ b/list.go @@ -152,7 +152,12 @@ func (e *Encoder) writeTypedList(v interface{}) error { var err error value := reflect.ValueOf(v) - + // https://github.com/apache/dubbo-go-hessian2/issues/317 + // if list is null, just return 'N' + if value.IsNil() { + e.buffer = encByte(e.buffer, BC_NULL) // 'N' + return nil + } // check ref if n, ok := e.checkRefMap(value); ok { e.buffer = encRef(e.buffer, n) diff --git a/list_test.go b/list_test.go index 65783669..849e9bbd 100644 --- a/list_test.go +++ b/list_test.go @@ -207,6 +207,19 @@ func TestListEncode(t *testing.T) { testJavaDecode(t, "customArgTypedFixedList_Object", []Object{new(A0)}) } +func TestNilList(t *testing.T) { + var List []*A0 + e := NewEncoder() + _ = e.Encode(List) + + d := NewDecoder(e.Buffer()) + res, err := d.Decode() + if err != nil { + t.Fail() + } + assert.Nil(t, res) +} + type TypedListTest struct { A *A0 List [][]*A0