wvteijlingen / Spine

A Swift library for working with JSON:API APIs. It supports mapping to custom model classes, fetching, advanced querying, linking and persisting.
MIT License
266 stars 109 forks source link

Added a serialization option to prevent serializing null values #87

Closed richardmcclellan closed 8 years ago

richardmcclellan commented 8 years ago

In cases where you don't want to serialize null values, you can now use the SerializationOption, OmitNullValues.

wvteijlingen commented 8 years ago

Thanks! Could you please also add a test to SerializingTests for this?

richardmcclellan commented 8 years ago

Sure, I've added a test!

wvteijlingen commented 8 years ago

Nice. But I'm wondering, in what cases would you want to omit null values?

richardmcclellan commented 8 years ago

@wvteijlingen In the API I am currently working with, if I set an attribute to null on a resource, it will also set that value to null on the server side. I have a UI which updates only a subset of the attributes of a resource, so when I am updating that subset, I want to make sure that only the relevant attributes are sent up, and there is no way for any other attributes to be accidentally changed.

wvteijlingen commented 8 years ago

Ah, makes sense. That's a good case for implementing something like dirty checking, but in the meantime, this will work. Thanks again!

wvteijlingen commented 8 years ago

I've started working on implementing dirty checking in this branch: https://github.com/wvteijlingen/Spine/tree/dirty-checking.

Since you seem to have the perfect use case for it, you might want to try it. If you do, please let me know whether this works for you!

markst commented 8 years ago

cheers @richardmcclellan.

Is there anyway I can set this is a global default? or perhaps to always do so on a POST operation?

https://github.com/wvteijlingen/Spine/blob/master/Spine/Operation.swift#L250

richardmcclellan commented 8 years ago

hi @markst!

For my use case, I was actually only using the serialization part of this library, so some more work may be required in order to utilize the OmitNullValues option when using Spine's networking interface.

markst commented 8 years ago

thanks for response @richardmcclellan I've made an issue here https://github.com/wvteijlingen/Spine/issues/94