Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 版本里面structtomap 存在一个bug #222

Open
supermigo opened this issue May 25, 2024 · 1 comment
Open

v2 版本里面structtomap 存在一个bug #222

supermigo opened this issue May 25, 2024 · 1 comment

Comments

@supermigo
Copy link

supermigo commented May 25, 2024

1 在转化的过程会吧deciaml 类型转化成map[] 这是个灾难,

2质疑一定要把所有的成员的类型全部转化成map 么, ?

3 是否把成员的struct 类型用interface 直接返回更安全呢? 特别遇到自定义类型又没有定json tag 的类型
如果第三点是成立的那么func (f *Field) mapValue(value any) any {
```
val := pointer.ExtractPointer(value)
v := reflect.ValueOf(val)
var ret any

switch v.Kind() {
case reflect.Struct:
        ret = v.Interface()


func main() {
	type TempStruct struct {
		Ip   string                 `json:"ip"`
		Data decimal.Decimal        `json:"data"`
		Temp map[string]interface{} `json:"temp"`
		X    complex128             `json:"x"`
	}
	type BigData struct {
		CCC  string     `json:"CCC"`
		Data TempStruct `json:"data"`
	}
	tempdata := &TempStruct{
		Ip:   "aaa",
		Data: decimal.NewFromInt(10),
		Temp: map[string]interface{}{
			"aaa": "bbb",
		},
		X: complex(1, 2),
	}
	bigdata := BigData{
		CCC:  "123123",
		Data: *tempdata,
	}

	t, _ := convertor2.StructToMap(bigdata)
	fmt.Printf("----->>>>>%+v", t)
	//fmt.Printf("----->>>>>%+v", t["data"].(TempStruct).Temp)
	//fmt.Printf("%+v\n", structs.New(tempdata))
	//fmt.Println(convertor.StructToMap(tempdata))

}

4
测试用例:
@duke-git
Copy link
Owner

@supermigo 可以提PR修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants