diff --git a/util/gconv/gconv_map.go b/util/gconv/gconv_map.go index 13f7d5e8f..c42f8e007 100644 --- a/util/gconv/gconv_map.go +++ b/util/gconv/gconv_map.go @@ -115,6 +115,10 @@ func doMapConvert(value interface{}, recursive bool, tags ...string) map[string] for k, v := range r { dataMap[k] = v } + case map[string]string: + for k, v := range r { + dataMap[k] = v + } case map[string]interface{}: if recursive { // A copy of current map. @@ -210,10 +214,8 @@ func doMapConvertForMapOrStructValue(isRoot bool, value interface{}, recursive b tags..., ) } - if len(dataMap) == 0 { - return value - } return dataMap + case reflect.Struct: // Map converting interface check. if v, ok := value.(iMapStrAny); ok { diff --git a/util/gconv/gconv_scan.go b/util/gconv/gconv_scan.go index 4cfa30cb7..426b699e8 100644 --- a/util/gconv/gconv_scan.go +++ b/util/gconv/gconv_scan.go @@ -105,7 +105,6 @@ func Scan(params interface{}, pointer interface{}, mapping ...map[string]string) return doStructs(params, pointer, keyToAttributeNameMapping, "") default: - return doStruct(params, pointer, keyToAttributeNameMapping, "") } } diff --git a/util/gconv/gconv_z_unit_struct_test.go b/util/gconv/gconv_z_unit_struct_test.go index 7a31cb8fd..75e8adbb7 100644 --- a/util/gconv/gconv_z_unit_struct_test.go +++ b/util/gconv/gconv_z_unit_struct_test.go @@ -7,14 +7,15 @@ package gconv_test import ( + "testing" + "time" + "github.com/gogf/gf/v2/container/gvar" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/internal/json" "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/util/gconv" - "testing" - "time" ) func Test_Struct_Basic1(t *testing.T) { @@ -1244,3 +1245,16 @@ func Test_Struct_MapAttribute(t *testing.T) { t.AssertNil(err) }) } + +func Test_Struct_Empty_MapStringString(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + type S struct { + Id int + } + var ( + s = &S{} + err = gconv.Struct(map[string]string{}, s) + ) + t.AssertNil(err) + }) +}