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

Undefined vs. nil #1127

Open
jpmcglone opened this issue May 20, 2022 · 1 comment
Open

Undefined vs. nil #1127

jpmcglone opened this issue May 20, 2022 · 1 comment

Comments

@jpmcglone
Copy link

When I write to JSON, I'd sometimes like to write:

"test": null

But other times just omit "test".

I made a simple struct that has undefined, null, or defined(Value) -- but I cannot for the life of me figure out how to make it generate some keys with "null" and omit others.

@clearbrian
Copy link

I found this but i tried true/false and it doesnt seem to work

ignoreNil

if my field is null its never output as JSON no matter if ignoreNil is true or false

func mapping(map: Map){
    name <- map["name", ignoreNil: true]
}

see IgnoreNilTests.swift in the repo for example

it is required because I call an API for another dev team in our company and they complain because my request isnt EXACTLY the same as the one they use on the web. So i need to send ALL fields as JSOn event the null ones.

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

No branches or pull requests

2 participants