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

added always_omitempty and always_omitnil flags to encoding_json.Marshal_Options #4857

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jkenda
Copy link
Contributor

@jkenda jkenda commented Feb 18, 2025

Not sure if this belongs in the core library but I got sick of writing "omitempty" next to every Maybe so I added these flags.

@@ -345,6 +354,27 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:

case runtime.Type_Info_Struct:
is_omitempty :: proc(v: any) -> bool {
v := v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use reflect.length instead.

return false
}

is_omitnil :: proc(v: any) -> bool {
v := v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use reflect.is_nil

@jkenda
Copy link
Contributor Author

jkenda commented Feb 19, 2025

reflect.length(x) == 0 and is_omitempty(x) are not always equal which will cause backwards incompatibility. reflect.length gives a more accurate result so I'm guessing that's okay?

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.

2 participants