On Sun, Sep 8, 2013 at 6:52 AM, simbo1905 <
masse...@gmail.com> wrote:
> Someone doing some browerside programming with that json may be expecting
> undefined not null of members which are none.
This isn't as clear cut as you think, the difference between the field
not included and it included but it is set to none. The default
behaviour maintains as much info as possible, and if we receive json
we handle both null and field not existing as None so you get the
behaviour you expect when sending data to the server. Having said all
that, this is just the default behaviour because it is the safest and
most complete representation.
> Is there a way to suppress the null entries such that the None values simply
> don't turn up in the string?
I wish there was a simple way I could point you at, but you end up
losing some of the benefit of the convenience functions when you don't
follow the default behaviour. Approaches to dealing with it are:
- Define a custom EncodeJson that uses the `:=?` and `->?:`
operators (an example can be seen at
http://argonaut.io/doc/json/).
These let you build a json structure that skips the field when it is
none.
- Define a post-processing step. Although this may have some
non-trivial performance impact if your json is large. Something like.
fred.asJson.withObject(o => /* filter out nulls on certain fields */)
There are possibly, better ways we could support this by using type
tags to give you the different behaviour. I have raised
https://github.com/argonaut-io/argonaut/issues/66 to look at it
further because this need has come up a few times recently.
Hopefully this will give you some ideas, if not I will try to do
something to make it easier, but it probably won't be until next week.
Cheers
Mark