Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: Proposal - Flexible omitempty #45787

Closed
PumpkinSeed opened this issue Apr 26, 2021 · 1 comment
Closed

encoding/json: Proposal - Flexible omitempty #45787

PumpkinSeed opened this issue Apr 26, 2021 · 1 comment

Comments

@PumpkinSeed
Copy link

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
}
@ianlancetaylor
Copy link
Contributor

Dup of #32675, see discussion at #11939.

@golang golang locked and limited conversation to collaborators Apr 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants