We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
similar to #459
package main import ( stdjson "encoding/json" "fmt" gojson "github.com/goccy/go-json" ) type Common struct { Domains []string `json:"domains,omitempty" binding:"required,gte=1,lte=3,unique,dive,required"` } type App struct { ID uint `json:"id,omitempty"` Type string `json:"type,omitempty"` Common } type Data struct { App } type AppGetResponse struct { TotalCount int `json:"totalCount"` Data []Data `json:"data,omitempty"` } func main() { totalCount := 1 resp := AppGetResponse{TotalCount: totalCount} resp.Data = make([]Data, totalCount) resp.Data[0] = Data{ App: App{ ID: 1, Type: "custom", Common: Common{ Domains: nil, }, }, } b1, _ := stdjson.Marshal(resp) // ok fmt.Println(string(b1)) b2, _ := gojson.Marshal(resp) // panic! fmt.Println(string(b2)) }
{"totalCount":1,"data":[{"id":1,"type":"custom"}]} panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11052fc] goroutine 1 [running]: github.com/goccy/go-json/internal/encoder/vm.Run(0xc0000a2dd0, {0xc0000f2000?, 0x0?, 0x0?}, 0x0?) /Users/raymond_liu/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/vm/vm.go:26 +0x7c github.com/goccy/go-json.encodeRunCode(0xc0000f1e28?, {0xc0000f2000?, 0x129bdc0?, 0xc0000b20c0?}, 0xc0000f2400?) /Users/raymond_liu/go/pkg/mod/github.com/goccy/[email protected]/encode.go:310 +0x68 github.com/goccy/go-json.encode(0xc0000a2dd0, {0x1146540, 0xc0000d60a0}) /Users/raymond_liu/go/pkg/mod/github.com/goccy/[email protected]/encode.go:235 +0x21f github.com/goccy/go-json.marshal({0x1146540, 0xc0000d60a0}, {0x0, 0x0, 0xc0000f1f50?}) /Users/raymond_liu/go/pkg/mod/github.com/goccy/[email protected]/encode.go:150 +0xb9 github.com/goccy/go-json.MarshalWithOption(...) /Users/raymond_liu/go/pkg/mod/github.com/goccy/[email protected]/json.go:186 github.com/goccy/go-json.Marshal({0x1146540?, 0xc0000d60a0?}) /Users/raymond_liu/go/pkg/mod/github.com/goccy/[email protected]/json.go:171 +0x2a main.main() /Users/raymond_liu/GolandProjects/awesomeProject/main.go:44 +0x126 Process finished with the exit code 2
package main import ( stdjson "encoding/json" "fmt" gojson "github.com/goccy/go-json" ) type Common struct { Domains []string `json:"domains,omitempty" binding:"required,gte=1,lte=3,unique,dive,required"` } type App struct { Common // move embedded struct here ID uint `json:"id,omitempty"` Type string `json:"type,omitempty"` } type Data struct { App } type AppGetResponse struct { TotalCount int `json:"totalCount"` Data []Data `json:"data,omitempty"` } func main() { totalCount := 1 resp := AppGetResponse{TotalCount: totalCount} resp.Data = make([]Data, totalCount) resp.Data[0] = Data{ App: App{ ID: 1, Type: "custom", Common: Common{ Domains: nil, }, }, } b1, _ := stdjson.Marshal(resp) // ok fmt.Println(string(b1)) b2, _ := gojson.Marshal(resp) // different result! fmt.Println(string(b2)) }
{"totalCount":1,"data":[{"id":1,"type":"custom"}]} {"totalCount":1,"data":[{}]}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Panic !!!
similar to #459
Got different result with stdjson
The text was updated successfully, but these errors were encountered: