On Thursday, September 29, 2016 at 4:25:25 PM UTC+1, Rupert Smith wrote:
>
> Some scnearios that would need to be covered:
>>
>
I also have a little problem with the 'roles' encode to solve. At the 
moment I have:

        , ( "roles"
          , case model.roles of
                Just roles ->
                    roles |> List.map roleEncoder |> Encode.list

                Nothing ->
                    Encode.null
          ) 

which will mean 'null' is output when the roles are Nothing. Which is not 
what I really want, as an explicit null will be interpreted by the server 
as meaning 'set the roles to null', whereas what I really want is no roles 
field set at all which the server will interpret as 'don't change the 
roles, they are not being defined by this request'.

But Encode.object takes a list of (String, Value) -> Value and its easiest 
for me to write this as an entry in a list rather than build up the list 
more conditionally. I suppose I could output a list of Maybe Value and then 
use the filter to remove Nothings from that list to arrive at a list of 
Value just for fields that are not Nothing.

I suppose what I am trying to point out, is that auto generating encoders 
and decoders requires dealing with a lot of different conventions depending 
on how you want it done. If I was using something like jackson in Java, the 
behaviour would be controlled by a set of flags when building the parsers, 
like "allowNoQuotes", "allowMissingFields", and so on. I think any attempt 
at auto generating would need to look at a good number of common variations 
in how json is treated and provide options to deal with them, in order to 
not be overly restrictive and useful.

-- 
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