Skip to content
Permalink
Browse files
update load pojo repository (#287)
Co-authored-by: binbin <binbin@didiglobal.com>
  • Loading branch information
sanxun0325 and binbin committed Nov 15, 2021
1 parent 3a4ef0b commit ad93624278b2ece6555d533664e957e2902bf8a5
Showing 3 changed files with 9 additions and 9 deletions.
@@ -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)
}
@@ -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))
@@ -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,20 +341,21 @@ 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
}
return s.index, true
}

// 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()

0 comments on commit ad93624

Please sign in to comment.