This is an automated email from the ASF dual-hosted git repository.
wongoo 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 eb7cef0 fix: can't duplicately decode Serializer object (#144)
eb7cef0 is described below
commit eb7cef0d6b93cc9aec2f000029ca399c33d99169
Author: 望哥 <[email protected]>
AuthorDate: Fri Dec 13 23:04:55 2019 -0600
fix: can't duplicately decode Serializer object (#144)
* fix: can't duplicately decode Serializer object
* separate imports
---
Makefile | 6 ++++++
object.go | 12 +++++++++---
serialize.go | 10 +++++++---
serialize_test.go | 22 ++++++++++++++++++++++
.../src/main/java/test/TestCustomReply.java | 10 ++++++++++
5 files changed, 54 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
index 0732d1e..0123897 100644
--- a/Makefile
+++ b/Makefile
@@ -18,5 +18,11 @@ lint:
lint2:
golangci-lint run
+
+format:
+ go fmt
+
test:
go test
+
+all: format test
\ No newline at end of file
diff --git a/object.go b/object.go
index 94f35eb..4756148 100644
--- a/object.go
+++ b/object.go
@@ -550,9 +550,7 @@ func (d *Decoder) decObject(flag int32) (interface{},
error) {
cls, _ = clsDef.(classInfo)
//add to slice
d.appendClsDef(cls)
- if c, ok := GetSerializer(cls.javaName); ok {
- return c.DecObject(d)
- }
+
return d.DecodeValue()
case tag == BC_OBJECT:
@@ -572,6 +570,10 @@ func (d *Decoder) decObject(flag int32) (interface{},
error) {
return d.decEnum(cls.javaName, TAG_READ)
}
+ if c, ok := GetSerializer(cls.javaName); ok {
+ return c.DecObject(d, typ, cls)
+ }
+
return d.decInstance(typ, cls)
case BC_OBJECT_DIRECT <= tag && tag <=
(BC_OBJECT_DIRECT+OBJECT_DIRECT_MAX):
@@ -586,6 +588,10 @@ func (d *Decoder) decObject(flag int32) (interface{},
error) {
return d.decEnum(cls.javaName, TAG_READ)
}
+ if c, ok := GetSerializer(cls.javaName); ok {
+ return c.DecObject(d, typ, cls)
+ }
+
return d.decInstance(typ, cls)
default:
diff --git a/serialize.go b/serialize.go
index 829a83e..08cc45e 100644
--- a/serialize.go
+++ b/serialize.go
@@ -18,6 +18,10 @@
package hessian
import (
+ "reflect"
+)
+
+import (
big "github.com/dubbogo/gost/math/big"
)
@@ -28,7 +32,7 @@ func init() {
type Serializer interface {
EncObject(*Encoder, POJO) error
- DecObject(*Decoder) (interface{}, error)
+ DecObject(*Decoder, reflect.Type, classInfo) (interface{}, error)
}
var serializerMap = make(map[string]Serializer, 16)
@@ -53,8 +57,8 @@ func (DecimalSerializer) EncObject(e *Encoder, v POJO) error {
return e.encObject(decimal)
}
-func (DecimalSerializer) DecObject(d *Decoder) (interface{}, error) {
- dec, err := d.DecodeValue()
+func (DecimalSerializer) DecObject(d *Decoder, typ reflect.Type, cls
classInfo) (interface{}, error) {
+ dec, err := d.decInstance(typ, cls)
if err != nil {
return nil, err
}
diff --git a/serialize_test.go b/serialize_test.go
index addfb65..1dff269 100644
--- a/serialize_test.go
+++ b/serialize_test.go
@@ -69,3 +69,25 @@ func doTestDecimal(t *testing.T, method, content string) {
assert.Equal(t, content, r.(*big.Decimal).String())
})
}
+
+func TestDecimalListGoDecode(t *testing.T) {
+ data := []string{
+ "123.4",
+ "123.45",
+ "123.456",
+ }
+
+ out, err := decodeJavaResponse(`customReplyTypedFixedList_BigDecimal`,
``, false)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ resp := out.([]*big.Decimal)
+ for i := range data {
+ gotDecimal := resp[i]
+ if gotDecimal.String() != data[i] {
+ t.Errorf("java: %s go: %s", gotDecimal.String(),
data[i])
+ }
+ }
+}
diff --git a/test_hessian/src/main/java/test/TestCustomReply.java
b/test_hessian/src/main/java/test/TestCustomReply.java
index 6b40ac3..1f32a7e 100644
--- a/test_hessian/src/main/java/test/TestCustomReply.java
+++ b/test_hessian/src/main/java/test/TestCustomReply.java
@@ -350,6 +350,16 @@ public class TestCustomReply {
output.flush();
}
+ public void customReplyTypedFixedList_BigDecimal() throws Exception {
+ BigDecimal[] decimals = new BigDecimal[]{
+ new BigDecimal("123.4"),
+ new BigDecimal("123.45"),
+ new BigDecimal("123.456"),
+ };
+ output.writeObject(decimals);
+ output.flush();
+ }
+
public void customReplyTypedFixedDateNull() throws Exception {
DateDemo demo = new DateDemo("zhangshan", null, null);
output.writeObject(demo);