CAICAIIs commented on code in PR #3175:
URL: https://github.com/apache/dubbo-go/pull/3175#discussion_r2725111553


##########
filter/generic/generalizer/bean.go:
##########
@@ -0,0 +1,238 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package generalizer
+
+import (
+       "reflect"
+       "sync"
+)
+
+import (
+       hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3/protocol/dubbo/hessian2"
+)
+
+// JavaBeanDescriptor type constants
+const (
+       TypeClass      = 1
+       TypeEnum       = 2
+       TypeCollection = 3
+       TypeMap        = 4
+       TypeArray      = 5
+       TypePrimitive  = 6
+       TypeBean       = 7
+)
+
+// JavaBeanDescriptor corresponds to 
org.apache.dubbo.common.beanutil.JavaBeanDescriptor
+type JavaBeanDescriptor struct {
+       ClassName  string      `json:"className"`
+       Type       int         `json:"type"`
+       Properties map[any]any `json:"properties"`
+}
+
+// JavaClassName implements hessian.POJO
+func (d *JavaBeanDescriptor) JavaClassName() string {
+       return "org.apache.dubbo.common.beanutil.JavaBeanDescriptor"
+}
+
+func init() {
+       hessian.RegisterPOJO(&JavaBeanDescriptor{})
+}
+
+var (
+       beanGeneralizer     Generalizer
+       beanGeneralizerOnce sync.Once
+)
+
+func GetBeanGeneralizer() Generalizer {
+       beanGeneralizerOnce.Do(func() {
+               beanGeneralizer = &BeanGeneralizer{}
+       })
+       return beanGeneralizer
+}
+
+// BeanGeneralizer converts objects to/from JavaBeanDescriptor format
+type BeanGeneralizer struct{}
+
+func (g *BeanGeneralizer) Generalize(obj any) (any, error) {
+       if obj == nil {
+               return nil, nil
+       }
+       return g.toDescriptor(obj), nil
+}
+
+func (g *BeanGeneralizer) Realize(obj any, typ reflect.Type) (any, error) {
+       if obj == nil {
+               return nil, nil
+       }
+       return GetMapGeneralizer().Realize(g.fromDescriptor(obj), typ)
+}
+
+func (g *BeanGeneralizer) GetType(obj any) (typ string, err error) {
+       typ, err = hessian2.GetJavaName(obj)
+       // no error or error is not NilError
+       if err == nil || err != hessian2.NilError {
+               return
+       }
+
+       // fallback to java.lang.Object for nil or unrecognized types
+       typ = "java.lang.Object"
+       err = nil
+       return
+}
+
+// toDescriptor converts Go object to JavaBeanDescriptor
+func (g *BeanGeneralizer) toDescriptor(obj any) *JavaBeanDescriptor {

Review Comment:
   已加检测是否循环引用的方法并加对应test



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to