Skip to content
Permalink
Browse files
Merge pull request #296 from sanxun0325/java_interger_null
support java integer null
  • Loading branch information
AlexStocks committed Dec 6, 2021
2 parents 49f9da8 + df62010 commit 75ff95074949d1f520f1eaee191472fecbb45eab
Showing 6 changed files with 66 additions and 1 deletion.
@@ -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 {
3 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)
}
@@ -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))
@@ -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}})
}
@@ -22,10 +22,12 @@
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 void customReplyJsonString() throws Exception {
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);
@@ -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 void setName(String name) {
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 + '\'' +
'}';
}
}

0 comments on commit 75ff950

Please sign in to comment.