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 df62010 support java integer null
new 75ff950 Merge pull request #296 from sanxun0325/java_interger_null
df62010 is described below
commit df620103579cea31934dad311d3dd60ea810af5f
Author: sanxun0325 <bbz17640380550.com>
AuthorDate: Fri Dec 3 23:20:19 2021 +0800
support java integer null
---
codec.go | 6 +++++-
int.go | 3 +++
int_test.go | 1 +
object_test.go | 19 +++++++++++++++++++
test_hessian/src/main/java/test/TestCustomReply.java | 20 ++++++++++++++++++++
test_hessian/src/main/java/test/model/User.java | 18 ++++++++++++++++++
6 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/codec.go b/codec.go
index 425468c..2055a12 100644
--- a/codec.go
+++ b/codec.go
@@ -455,7 +455,11 @@ func ConvertSliceValueType(destTyp reflect.Type, v
reflect.Value) (reflect.Value
if cv, ok := item.(reflect.Value); ok {
itemValue = cv
} else {
- itemValue = reflect.ValueOf(item)
+ if item == nil {
+ itemValue = reflect.Zero(destTyp.Elem())
+ } else {
+ itemValue = reflect.ValueOf(item)
+ }
}
if !elemPtrType && itemValue.Kind() == reflect.Ptr {
diff --git a/int.go b/int.go
index dd06d11..06cdb71 100644
--- a/int.go
+++ b/int.go
@@ -102,6 +102,9 @@ func (d *Decoder) decInt32(flag int32) (int32, error) {
err = binary.Read(d.reader, binary.BigEndian, &i32)
return i32, perrors.WithStack(err)
+ case tag == BC_NULL:
+ return int32(0), nil
+
default:
return 0, perrors.Errorf("decInt32 integer wrong tag:%#x", tag)
}
diff --git a/int_test.go b/int_test.go
index 0c98ff6..441bca3 100644
--- a/int_test.go
+++ b/int_test.go
@@ -116,6 +116,7 @@ func TestEncInt32Len4B(t *testing.T) {
}
func TestInt(t *testing.T) {
+ testDecodeFramework(t, "replyNull", nil)
testDecodeFramework(t, "replyInt_0", int32(0))
testDecodeFramework(t, "replyInt_0x30", int32(0x30))
testDecodeFramework(t, "replyInt_0x3ffff", int32(0x3ffff))
diff --git a/object_test.go b/object_test.go
index f2d1e4f..d6d67b1 100644
--- a/object_test.go
+++ b/object_test.go
@@ -897,3 +897,22 @@ func TestWrapperClassArray(t *testing.T) {
da := &DoubleArray{Values: []float64{1.0, 100.0, 10000.1}}
assert.True(t, reflect.DeepEqual(got, da))
}
+
+type User struct {
+ Id int32
+ List []int32
+}
+
+func (u *User) JavaClassName() string {
+ return "test.model.User"
+}
+
+func TestDecodeIntegerHasNull(t *testing.T) {
+ RegisterPOJO(&User{})
+ testDecodeFramework(t, "customReplyTypedIntegerHasNull", &User{Id: 0})
+}
+
+func TestDecodeSliceIntegerHasNull(t *testing.T) {
+ RegisterPOJO(&User{})
+ testDecodeFramework(t, "customReplyTypedListIntegerHasNull", &User{Id:
0, List: []int32{1, 0}})
+}
diff --git a/test_hessian/src/main/java/test/TestCustomReply.java
b/test_hessian/src/main/java/test/TestCustomReply.java
index 3ae19de..8d22362 100644
--- a/test_hessian/src/main/java/test/TestCustomReply.java
+++ b/test_hessian/src/main/java/test/TestCustomReply.java
@@ -22,10 +22,12 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.caucho.hessian.test.A0;
import com.caucho.hessian.test.A1;
+import com.caucho.hessian.test.TestObject;
import test.generic.BusinessData;
import test.generic.Response;
import test.model.CustomMap;
import test.model.DateDemo;
+import test.model.User;
import java.io.OutputStream;
import java.io.Serializable;
@@ -92,6 +94,24 @@ public class TestCustomReply {
output.flush();
}
+ public void customReplyTypedIntegerHasNull() throws Exception {
+ User user = new User();
+ user.setId(null);
+ output.writeObject(user);
+ output.flush();
+ }
+
+ public void customReplyTypedListIntegerHasNull() throws Exception {
+ User user = new User();
+ user.setId(null);
+ List<Integer> list = new ArrayList<>();
+ list.add(1);
+ list.add(null);
+ user.setList(list);
+ output.writeObject(user);
+ output.flush();
+ }
+
public void customReplyTypedFixedListHasNull() throws Exception {
Object[] o = new Object[]{new A0(), new A1(), null};
output.writeObject(o);
diff --git a/test_hessian/src/main/java/test/model/User.java
b/test_hessian/src/main/java/test/model/User.java
index a9f5e52..2a0538a 100644
--- a/test_hessian/src/main/java/test/model/User.java
+++ b/test_hessian/src/main/java/test/model/User.java
@@ -18,10 +18,15 @@
package test.model;
import java.io.Serializable;
+import java.util.List;
public class User implements Serializable {
private String name;
+ private Integer id;
+
+ private List<Integer> list;
+
public User() {
}
@@ -37,10 +42,23 @@ public class User implements Serializable {
this.name = name;
}
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public List<Integer> getList() { return list; }
+
+ public void setList(List<Integer> list) { this.list = list; }
+
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
+ "id='" + id + '\'' +
'}';
}
}