Quicktype option parameter handling

414 Views Asked by At

I have an optional parameter in my web-service response which can or can not return null. What will be the best what to manage those?

As if I pass null in creator lets say for this structure:

{
    "email": "[email protected]",
    "profilePicture": null,
    "firstTime": true,
    "preference1": {
        "$id": "26",
        "$values": []
    },
    "Preference2": {
        "$id": "27",
        "$values": []
    }
}

Now profilePicture is set to JSONNull and next time when I actually get profile URL it will not parse that and my response data to LNUser is nil. If I set this variable to String and null received response get set to nil.

2

There are 2 best solutions below

0
Shehata Gamal On BEST ANSWER

You need

let profilePicture:URL?
0
David Siegel On

quicktype needs an exhaustive set of examples, so make sure one of your samples includes a non-null value. Like this: https://app.quicktype.io?share=ldXiDP9cIKB1Q7CPJ7Id