gf
gf copied to clipboard
encoding/gjson: 没有正确处理omitempty
Go version
go1.24.0 windows/amd64
GoFrame version
2.7.0
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
比如以下测试代码:
func main() {
abc := MyTest{
Age: 1,
}
g.Dump("gjson:", gjson.New(abc).String())
jsonStr, _ := json.Marshal(abc)
g.Dump("json:", jsonStr)
}
type MyTest struct {
Age int `json:"age,omitempty"`
Height int `json:"height,omitempty"`
}
What did you see happen?
输出为:
"gjson:"
"{age:1,height:0}"
"json:"
"{age:1}"
What did you expect to see?
gjson转换结构体应该与json包的结果一致
想要和标准库的json包序列化结果一致就是用gjson.MustEncodeString()