how use json null set sql time field to null?
- defind web api dto struct
type Dto struct {
Start null.Time
}
- send this json to web api
{
"Start": null
}
- service: use gorm update entry
gorm.Model(&MyTable).Where("id = 1").Update(&dto)
- Hope to generate sql
update my_table set start = null where id = 1
The start field is now ignored when used in this way
Sounds like a GORM issue to me. I don't use it and I can't provide support for it.
I would suggest that after you unmarshal the JSON input, check whether null.Time is properly set to null or not. If it looks OK, then it's almost certainly a GORM issue.
The result is the same whether the time type is passed or not, how to set a zero value for the time

I feel a better option would be to use the Golang stdlib data structures for null SQL values. Those will generally be supported by all Golang ORMs, including GORM as their documentation on model declaration specifically uses them (https://gorm.io/docs/models.html).
The relevant type here would be: sql.NullTime (https://pkg.go.dev/database/sql#NullTime)
Unfortunately, you will need to have logic to copy the data from the source type into the destination type. However, you would have incurred that "extra" step no matter what.