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


##########
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:
   done
   



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