Merge pull request #201 from fangyincheng/ignore_fields
Ignore fields
diff --git a/binary_test.go b/binary_test.go
index dafda34..c145e13 100644
--- a/binary_test.go
+++ b/binary_test.go
@@ -20,8 +20,6 @@
import (
"bytes"
"fmt"
-
- // "fmt"
"testing"
)
diff --git a/int_test.go b/int_test.go
index 726a11f..082f399 100644
--- a/int_test.go
+++ b/int_test.go
@@ -18,10 +18,13 @@
package hessian
import (
- "github.com/stretchr/testify/assert"
"testing"
)
+import (
+ "github.com/stretchr/testify/assert"
+)
+
func TestEncInt32Len1B(t *testing.T) {
var (
v int32
diff --git a/object.go b/object.go
index d629933..e2ef7b3 100644
--- a/object.go
+++ b/object.go
@@ -377,7 +377,8 @@
index, fieldStruct, err := findFieldWithCache(fieldName, typ)
if err != nil {
- return nil, perrors.Errorf("can not find field %s", fieldName)
+ d.DecodeValue()
+ continue
}
// skip unexported anonymous field
@@ -395,8 +396,8 @@
// unpack pointer to enable value setting
fldRawValue := UnpackPtrValue(field)
-
kind := fldTyp.Kind()
+
switch kind {
case reflect.String:
str, err := d.decString(TAG_READ)
diff --git a/object_test.go b/object_test.go
index 76654c7..db66596 100644
--- a/object_test.go
+++ b/object_test.go
@@ -25,6 +25,10 @@
"time"
)
+import (
+ "github.com/stretchr/testify/assert"
+)
+
type Department struct {
Name string
}
@@ -749,3 +753,18 @@
}
}
}
+
+type Person183 struct {
+ Name string
+}
+
+func (Person183) JavaClassName() string {
+ return `test.Person183`
+}
+
+func TestIssue183_DecodeExcessStructField(t *testing.T) {
+ RegisterPOJO(&Person183{})
+ got, err := decodeJavaResponse(`customReplyPerson183`, ``, false)
+ assert.NoError(t, err)
+ t.Logf("%T %+v", got, got)
+}
diff --git a/test_hessian/src/main/java/test/TestCustomReply.java b/test_hessian/src/main/java/test/TestCustomReply.java
index 4586e24..12fc411 100644
--- a/test_hessian/src/main/java/test/TestCustomReply.java
+++ b/test_hessian/src/main/java/test/TestCustomReply.java
@@ -425,6 +425,18 @@
output.flush();
}
+ public void customReplyPerson183() throws Exception {
+ Person183 p = new Person183();
+ p.name = "pname";
+ p.age = 13;
+ InnerPerson innerPerson = new InnerPerson();
+ innerPerson.name = "pname2";
+ innerPerson.age = 132;
+ p.innerPerson = innerPerson;
+ output.writeObject(p);
+ output.flush();
+ }
+
public void customReplyComplexString() throws Exception {
output.writeObject(TestString.getComplexString());
output.flush();
@@ -491,3 +503,14 @@
}
}
+
+class Person183 implements Serializable {
+ public String name;
+ public Integer age;
+ public InnerPerson innerPerson;
+}
+
+class InnerPerson implements Serializable {
+ public String name;
+ public Integer age;
+}
diff --git a/test_hessian/src/main/java/test/TestString.java b/test_hessian/src/main/java/test/TestString.java
index a19cb73..c026796 100644
--- a/test_hessian/src/main/java/test/TestString.java
+++ b/test_hessian/src/main/java/test/TestString.java
@@ -30,8 +30,8 @@
return s + ",max" + maxUnicode;
}
- public static String getComplexString() {
- String s = "킐\u0088中国你好!\u0088\u0088\u0088\u0088\u0088\u0088";
- return s;
- }
+ public static String getComplexString() {
+ String s = "킐\u0088中国你好!\u0088\u0088\u0088\u0088\u0088\u0088";
+ return s;
+ }
}