Skip to content

Commit

Permalink
Merge pull request #201 from fangyincheng/ignore_fields
Browse files Browse the repository at this point in the history
Ignore fields
  • Loading branch information
AlexStocks authored Jun 12, 2020
2 parents a019bcb + ac7ea8e commit 2319569
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
2 changes: 0 additions & 2 deletions binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package hessian
import (
"bytes"
"fmt"

// "fmt"
"testing"
)

Expand Down
5 changes: 4 additions & 1 deletion int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ func (d *Decoder) decInstance(typ reflect.Type, cls classInfo) (interface{}, err

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
Expand All @@ -395,8 +396,8 @@ func (d *Decoder) decInstance(typ reflect.Type, cls classInfo) (interface{}, err

// unpack pointer to enable value setting
fldRawValue := UnpackPtrValue(field)

kind := fldTyp.Kind()

switch kind {
case reflect.String:
str, err := d.decString(TAG_READ)
Expand Down
19 changes: 19 additions & 0 deletions object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
"time"
)

import (
"github.com/stretchr/testify/assert"
)

type Department struct {
Name string
}
Expand Down Expand Up @@ -749,3 +753,18 @@ func BenchmarkDecode(b *testing.B) {
}
}
}

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)
}
23 changes: 23 additions & 0 deletions test_hessian/src/main/java/test/TestCustomReply.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ public void customReplyStringEmoji() throws Exception {
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();
Expand Down Expand Up @@ -491,3 +503,14 @@ class TypedListTest implements Serializable {
}

}

class Person183 implements Serializable {
public String name;
public Integer age;
public InnerPerson innerPerson;
}

class InnerPerson implements Serializable {
public String name;
public Integer age;
}
8 changes: 4 additions & 4 deletions test_hessian/src/main/java/test/TestString.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static String getEmojiTestString() {
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;
}
}

0 comments on commit 2319569

Please sign in to comment.