On Thursday, September 29, 2016 at 2:40:38 PM UTC+1, Rupert Smith wrote:
>
> Some scnearios that would need to be covered:
>
> Optional fields:
>

In one of my json, I have an optional list of 'roles'. This might be the 
empty list, it might be an explicit 'null' or might be missing altogether. 
To decode this I had to do:
 
        |: (("roles" := maybeNull (Decode.list roleDecoder))
                |> withDefault Nothing
           )

phew. I suppose I could write my own helper function here called 
'maybeNullOrMissing'.

No quotes:

String don't seem to decode without quotes. I had an integer value that I 
wanted to just treat as a string, as its an id so I consider it opaque and 
for the maximum flexibility just treat it as a string. Since there were no 
quotes I had to do this:

        |: ("id" := Decode.int |> Decode.map toString)
 
Which would break if the server ever did return a non-integer string in 
quotes.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to