You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
stdjson "encoding/json""fmt""github.com/goccy/go-json"
)
typeCustomerstruct {
TKIDstring`gorm:"primarykey;not null;type:varchar(255);"`IDs []*IDMapping`gorm:"foreignKey:TKID;"`
}
typeIDMappingstruct {
TKIDstring`gorm:"comment:TKID;index:idx_tk_id;not null;type:varchar(255);"`Customer*Customer// when use MyCustomer will report an error when converted to json, Comment out this line and all serialization will not report errors
}
funcmain() {
typeMyCustomerstruct {
CustomerMyFieldstring
}
varlist= []MyCustomer{
{
Customer: Customer{
TKID: "1",
},
MyField: "111",
},
}
bs, err:=stdjson.Marshal(list) //1. std json no problemiferr!=nil {
panic(err)
}
fmt.Println("std json:", string(bs))
bs, err=json.Marshal(list[0].Customer) //2. goccy/go-json no problemiferr!=nil {
panic(err)
}
fmt.Println("goccy/go-json(customer):", string(bs))
bs, err=json.Marshal(list) //3. paniciferr!=nil {
panic(err)
}
fmt.Println("goccy/go-json:", string(bs))
}
As shown in the sample code, MyCustomer will report an error when converted to json(Note 3), but it will not report an error when using the json of the standard library(Note 1).
No error will occur when directly converting Customer without embedding(Note 2)
The text was updated successfully, but these errors were encountered:
Minimal reproducible code
As shown in the sample code, MyCustomer will report an error when converted to json(Note 3), but it will not report an error when using the json of the standard library(Note 1).
No error will occur when directly converting Customer without embedding(Note 2)
The text was updated successfully, but these errors were encountered: