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

Globally specify operation serializer options #94

Open markst opened 8 years ago

markst commented 8 years ago

We'd like to globally specify OmitNullValues as a default option when serializing, or perhaps even be able to specify endpoint specific options...

wvteijlingen commented 8 years ago

What is your use case for this? Perhaps there is a way we can solve it without adding any more configuration options.

markst commented 8 years ago

Current use case is as I mentioned, here's my Spine branch changes:

if isNewResource {
    URL = router.URLForResourceType(resource.resourceType)
    method = "POST"
    options = [.IncludeToOne, .IncludeToMany, .OmitNullValues]
} else {
    URL = router.URLForQuery(Query(resource: resource))
    method = "PATCH"
    options = [.IncludeID, .OmitNullValues]
}
wvteijlingen commented 8 years ago

Why do you want to omit null values? If it's because of overwriting attributes that weren't fetched, I recommend trying the dirty-checking branch.

markst commented 7 years ago

thanks @wvteijlingen yeah dirty checking also achieves what I wish for. However this still requires me to create an instance of SerializeOperation to be able to assign options.

I'd like to be able to globally specify all SerializeOperations always dirty check.