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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

omitempty also considers structs with all zero values "empty". #356

Merged
merged 1 commit into from Jun 7, 2022

Conversation

arp242
Copy link
Collaborator

@arp242 arp242 commented May 29, 2022

A common use case for this is time.Time, which will get marshaled
otherwise.

A struct with private fields set is not considered to be "empty"; not
sure yet if this is the best behaviour 馃 It is the easiest to implement
though.

Fixes #353

@arp242
Copy link
Collaborator Author

arp242 commented May 29, 2022

Actually, checking only exported fields doesn't really work; time.Time for example contains only unexported fields and everything is done through methods, so it will always be "empty".

I guess the current behaviour is fine.

A common use case for this is time.Time, which will get marshaled
otherwise.

A struct with private fields set is *not* considered to be "empty"; this
is because some structs (such as time.Time) contain only private fields.

Fixes #353
@arp242 arp242 merged commit 28ff18d into master Jun 7, 2022
@arp242 arp242 deleted the empty branch June 7, 2022 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant