ObjectMapper
ObjectMapper copied to clipboard
Undefined vs. nil
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.
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.