Closed rts-gordon closed 5 months ago
sql.NullString is a struct instead of a string. If you want use it as string, Please implement json.Unmarshaler
on it
Hi @AsterDY I implement json.Unmarshaler interface, it is works for encoding/json, but not works for sonic/Unmarshal. Which interface I should implment in sonic? thank you very much.
// NullString is an alias for sql.NullString data type
type NullString sql.NullString
// MarshalJSON for NullString
func (ns *NullString) MarshalJSON() ([]byte, error) {
if !ns.Valid {
return []byte("null"), nil
}
return json.Marshal(ns.String)
}
// UnmarshalJSON for NullString
func (ns *NullString) UnmarshalJSON(b []byte) error {
err := json.Unmarshal(b, &ns.String)
ns.Valid = (err == nil)
return err
}
Hi there,
There is a struct include a sql.NullString field, it will be failed when parse json data with this struct, is there any solution for this issue? Thank you.
error message: