ObjectMapper icon indicating copy to clipboard operation
ObjectMapper copied to clipboard

Undefined vs. nil

Open jpmcglone opened this issue 2 years ago • 1 comments

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.

jpmcglone avatar May 20 '22 18:05 jpmcglone

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.

clearbrian avatar Jun 28 '22 12:06 clearbrian