This is an automated email from the ASF dual-hosted git repository.
joezou 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 ad93624 update load pojo repository (#287)
ad93624 is described below
commit ad93624278b2ece6555d533664e957e2902bf8a5
Author: binbin.zhang <[email protected]>
AuthorDate: Mon Nov 15 22:08:55 2021 +0800
update load pojo repository (#287)
Co-authored-by: binbin <[email protected]>
---
java_sql_time.go | 2 +-
object.go | 7 +++----
pojo.go | 9 +++++----
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/java_sql_time.go b/java_sql_time.go
index ab4c022..18c2a49 100644
--- a/java_sql_time.go
+++ b/java_sql_time.go
@@ -86,7 +86,7 @@ func (JavaSqlTimeSerializer) EncObject(e *Encoder, vv POJO)
error {
}
}
if idx == -1 {
- idx, ok = checkPOJORegistry(typeof(vv))
+ idx, ok = checkPOJORegistry(vv)
if !ok {
idx = RegisterPOJO(v)
}
diff --git a/object.go b/object.go
index 0186992..84ee94e 100644
--- a/object.go
+++ b/object.go
@@ -106,18 +106,17 @@ func (e *Encoder) encObject(v interface{}) error {
clsDef *classInfo
)
pojo, isPojo := v.(POJO)
- vv := reflect.ValueOf(v)
-
// get none pojo JavaClassName
var nonePojoJavaName string
if !isPojo {
- s, ok := loadPOJORegistry(vv.Type().String())
+ s, ok := loadPOJORegistry(v)
if !ok {
return perrors.Errorf("non-pojo obj %s has not being
registered before!", typeof(v))
}
nonePojoJavaName = s.javaName
}
+ vv := reflect.ValueOf(v)
// check ref
if n, ok := e.checkRefMap(vv); ok {
e.buffer = encRef(e.buffer, n)
@@ -142,7 +141,7 @@ func (e *Encoder) encObject(v interface{}) error {
var ok bool
if idx == -1 {
- idx, ok = checkPOJORegistry(typeof(v))
+ idx, ok = checkPOJORegistry(v)
if !ok {
if reflect.TypeOf(v).Implements(javaEnumType) {
idx = RegisterJavaEnum(v.(POJOEnum))
diff --git a/pojo.go b/pojo.go
index 7f2118b..1257e9d 100644
--- a/pojo.go
+++ b/pojo.go
@@ -312,7 +312,7 @@ func RegisterJavaEnum(o POJOEnum) int {
default:
t.typ = reflect.TypeOf(o)
}
- t.goName = t.typ.String()
+ t.goName = getGoName(o)
t.javaName = o.JavaClassName()
t.inst = o
pojoRegistry.j2g[t.javaName] = t.goName
@@ -341,8 +341,8 @@ func RegisterJavaEnum(o POJOEnum) int {
}
// check if go struct name @goName has been registered or not.
-func checkPOJORegistry(goName string) (int, bool) {
- s, ok := loadPOJORegistry(goName)
+func checkPOJORegistry(v interface{}) (int, bool) {
+ s, ok := loadPOJORegistry(v)
if !ok {
return -1, false
}
@@ -350,11 +350,12 @@ func checkPOJORegistry(goName string) (int, bool) {
}
// load struct info if go struct name @goName has been registered or not.
-func loadPOJORegistry(goName string) (*structInfo, bool) {
+func loadPOJORegistry(v interface{}) (*structInfo, bool) {
var (
ok bool
s *structInfo
)
+ goName := getGoName(v)
pojoRegistry.RLock()
s, ok = pojoRegistry.registry[goName]
pojoRegistry.RUnlock()