go-json
go-json copied to clipboard
Panic
I cut structures for readability. It works with "encoding/json", but panics with "github.com/goccy/go-json"
package main
import (
"github.com/goccy/go-json"
)
// "encoding/json"
// "github.com/goccy/go-json"
type Auth struct {
Id int `json:"id"`
Login string `json:"login"`
CurrentOrganization *CurrentOrganization `json:"organization,omitempty" db:"organization"`
}
type CurrentOrganization struct {
Id int `json:"id"`
}
type User struct {
Auth
}
type AddUser struct {
User
}
func main() {
user := new(AddUser)
user.Login = "user756"
jsonUser, err := json.Marshal(user)
if err != nil {
println("error:", err.Error())
}
println("user:", jsonUser)
}
I understand, "omitempty" is the reason.
Thank you for your reports. This problem was fixed with https://github.com/goccy/go-json/pull/438