bosprimigenious commented on code in PR #1080:
URL: https://github.com/apache/dubbo-go-pixiu/pull/1080#discussion_r4527121918
##########
pkg/common/util/response.go:
##########
@@ -88,14 +88,15 @@ func mapIItoMapSI(in any) any {
outMap := make(map[string]any, len(inMap))
for k, v := range inMap {
- if v == nil {
- continue
- }
s := fmt.Sprint(k)
if s == "class" {
// ignore the "class" field
continue
}
+ if v == nil {
+ outMap[s] = nil
Review Comment:
你指出的 typed nil map/slice 问题在当前 HEAD 6690fb3 中仍然存在:现在只保留普通 nil,typed nil
容器还会进入 map/slice 转换分支。前一条总评论提到的 `IsNil()` 检查尚未推送,本条还需要代码修改。
##########
pkg/common/util/response_test.go:
##########
@@ -93,3 +95,77 @@ func TestNewDubboSliceResponse(t *testing.T) {
assert.Equal(t, "tc", r["name"])
assert.Equal(t, "bob", r["father"].(map[string]any)["name"])
}
+
+func TestNewDubboResponsePreservesNullMapValues(t *testing.T) {
+ var nullString *string
+ for _, tt := range []struct {
+ name string
+ input any
+ want string
+ humpWant string
+ }{
+ {
+ name: "string map",
+ input: map[string]any{"nullValue": nil, "zero": 0,
"false": false, "empty": ""},
+ want:
`{"nullValue":null,"zero":0,"false":false,"empty":""}`,
+ humpWant:
`{"null_value":null,"zero":0,"false":false,"empty":""}`,
+ },
+ {
+ name: "generic map",
+ input: map[any]any{"nullValue": nil, "zero": 0,
"false": false, "empty": "", "class": "java.util.Map"},
+ want:
`{"nullValue":null,"zero":0,"false":false,"empty":""}`,
+ humpWant:
`{"null_value":null,"zero":0,"false":false,"empty":""}`,
+ },
+ {
+ name: "nested generic map",
+ input: map[any]any{"child": map[any]any{"nullValue":
nil}},
+ want: `{"child":{"nullValue":null}}`,
+ humpWant: `{"child":{"null_value":null}}`,
+ },
+ {
+ name: "generic map in slice",
+ input: []any{map[any]any{"nullValue": nil}},
+ want: `[{"nullValue":null}]`,
+ humpWant: `[{"null_value":null}]`,
+ },
+ {
+ name: "nested string map",
+ input: map[any]any{"child":
map[string]any{"nullValue": nil}},
+ want: `{"child":{"nullValue":null}}`,
+ humpWant: `{"child":{"null_value":null}}`,
+ },
+ {
+ name: "typed nil value",
+ input: map[any]any{"nullValue": nullString},
Review Comment:
当前测试中的 typed nil 只覆盖 `*string`,确实缺少 typed nil map 和 slice。按前一条采用 null
语义的处理方向,这两类用例应断言 `null`,并与普通空 map/slice 的用例区分;这些补充目前还没有进入分支。
--
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]