Closed
Description
Questions unrelated.
I run into the issue where I wanted to omitempty a non-pointer struct. I couldn't make it happen properly so I think about a solution. So this is the code running I guess when there is the omitempty tag on the field. What if it would check for an extra interface implementation where we can flexibly determine when we consider a non-pointer struct as empty?
So use-case in this playground. It seems that the empty struct marshalled into the JSON. But if the Go has an interface like below I can implement this and the linked source can look for that implementation. If no any implementation than go with the default.
type Something interface {
IsEmpty() bool
}
Activity
ianlancetaylor commentedon Apr 26, 2021
Dup of #32675, see discussion at #11939.