AlexStocks commented on code in PR #3709:
URL: https://github.com/apache/dubbo-go/pull/3709#discussion_r3883641564


##########
filter/generic/generalizer/map.go:
##########
@@ -183,40 +187,61 @@ func objToMap(obj any) any {
                for i := 0; i < t.NumField(); i++ {
                        field := t.Field(i)
                        value := v.Field(i)
+                       tag := parseMTag(field)
+                       if tag.ignore || tag.omitEmpty && isEmptyValue(value) {
+                               continue
+                       }
                        kind := value.Kind()
                        if !value.CanInterface() {
                                logger.Debugf("[Filter][Generic] objToMap is 
skipped because it couldn't be converted to interface, field=%v", field)
                                continue
                        }
                        valueIface := value.Interface()
+                       var generalizedValue any
+                       var err error
                        switch kind {
                        case reflect.Pointer:
                                if value.IsNil() {
-                                       setInMap(result, field, nil)
-                                       continue
+                                       generalizedValue = nil
+                                       break
                                }
-                               setInMap(result, field, objToMap(valueIface))
+                               generalizedValue, err = objToMap(valueIface)
                        case reflect.Struct, reflect.Slice, reflect.Map:
                                if isPrimitive(valueIface) {
                                        logger.Warnf("[Filter][Generic] %q is 
primitive. Cross-language transfer (e.g., dubbo-go <-> dubbo-java) may crash. 
Use basic types like string.", value.Type())
-                                       setInMap(result, field, valueIface)
-                                       continue
+                                       generalizedValue = valueIface
+                                       break
                                }
 
-                               setInMap(result, field, objToMap(valueIface))
+                               generalizedValue, err = objToMap(valueIface)
                        default:
-                               setInMap(result, field, valueIface)
+                               generalizedValue = valueIface
+                       }
+                       if err != nil {
+                               return nil, err
                        }
+                       if tag.squash {
+                               squashed, ok := 
generalizedValue.(map[string]any)
+                               if !ok {
+                                       return nil, perrors.Errorf("cannot 
squash non-struct type '%s'", value.Type())
+                               }
+                               maps.Copy(result, squashed)

Review Comment:
   [P1] 当前修复会误删普通 squash 字段的 `class` 业务值
   
   这里无条件 `delete(squashed, "class")`,但 `squashed` 不一定来自 POJO。普通内层 struct 
如果声明一个映射到 `class` 的业务字段(例如 Go 字段 `Class` 配置 m tag `class`),通过 `m:",squash"` 
展开时本应保留为顶层 `class`,现在会被静默删除,generic 参数因此缺字段。旧的内层 POJO 类型元数据覆盖问题应只在内层值确实实现 
`hessian.POJO` 时移除类型元数据,或在复制后显式恢复外层 POJO 的 class。请同时补普通内层业务 `class` 字段和父子 POJO 
类型名不同的两类回归测试。



-- 
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