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

gjson.Json在继承的结构体中使用gconv.Scan转换后会导致值丢失,其他类型正常 #2381

Closed
bufanyun opened this issue Dec 30, 2022 · 0 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@bufanyun
Copy link

gjson.Json在继承的结构体中使用gconv.Scan转换后会导致值丢失,其他类型正常

gf version:v2.2.5

代码如下:

package main

import (
	"github.com/gogf/gf/v2/encoding/gjson"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gctx"
	"github.com/gogf/gf/v2/os/gtime"
	"github.com/gogf/gf/v2/util/gconv"
)

type Inherit struct {
	Id        int64       `json:"id"          description:"Id"`
	Flag      *gjson.Json `json:"flag"        description:"标签"`
	Title     string      `json:"title"       description:"标题"`
	CreatedAt *gtime.Time `json:"createdAt"   description:"创建时间"`
}

type Test1 struct {
	Inherit
}
type Test2 struct {
	Inherit
}

func main() {
	var (
		A1 Test1
		A2 Test2
	)

	A1 = Test1{
		Inherit{
			Id:        2,
			Flag:      gjson.New("[\"1\", \"2\"]"),
			Title:     "测试",
			CreatedAt: gtime.Now(),
		},
	}
	g.DumpWithType("A1", A1)

	if err := gconv.Scan(A1, &A2); err != nil {
		g.Log().Warningf(gctx.New(), "err:%v", err)
		return
	}
	g.DumpWithType("A2", A2)
}

运行结果:

./\test.exe 
build running pid: 14508
string(2) "A1"
main.Test1(4) {                                      
    Id:        int64(2),                             
    Flag:      *gjson.Json(13) "[\"1\",\"2\"]",      
    Title:     string(6) "测试",                     
    CreatedAt: *gtime.Time(19) "2022-12-30 09:49:53",
}
string(2) "A2"
main.Test2(4) {
    Id:        int64(2),
    Flag:      *gjson.Json(4) "null",
    Title:     string(6) "测试",
    CreatedAt: *gtime.Time(19) "2022-12-30 09:49:53",
}

gqcn added a commit that referenced this issue Dec 30, 2022
@gqcn gqcn added bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version. labels Dec 30, 2022
@gqcn gqcn closed this as completed Dec 30, 2022
gqcn added a commit that referenced this issue Jan 3, 2023
* fix issue #2381

* up

* up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

No branches or pull requests

2 participants