This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go-hessian2.git
The following commit(s) were added to refs/heads/master by this push:
new 097671a nil slice decode to empty slice
new 83d6845 Merge pull request #318 from mark4z/master
097671a is described below
commit 097671a525b0292996f59c73e3174b8d222eeb93
Author: mark4z <[email protected]>
AuthorDate: Sun Jul 3 15:03:51 2022 +0800
nil slice decode to empty slice
---
list.go | 7 ++++++-
list_test.go | 13 +++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/list.go b/list.go
index c89bc49..0ce242b 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 6578366..849e9bb 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