Hi Peter
This JSON behaviour presumably stems from the limitation on NSDictionary and
NSArray that they cannot contain nil objects, so NSNull is used instead.
There seem to be two popular workarounds if the client code requires nil
instead of NSNull:
1 - A category on NSDictionary, e.g. - (id)cmis_objectForKeyNotNull:(id)key { …
}
2 - A macro, e.g. NilOrObjectForKey(json, key) which would do the same thing.
Neither of those solutions would add too much overhead, although clearly we
would no longer benefit from modern Objective-C syntax in those instances.
I'm not currently up-to-speed with the browser binding branch, so can't comment
on your second issue.
Regards,
Mike
On 17 Apr 2014, at 13:17, Sutter, Peter <[email protected]> wrote:
> Hi there,
>
> I’m facing currently an issue with [NSJSONSerialization
> JSONObjectWithData:options:error:] and would like to hear your opinion.
> The method returns for keys that do not have a value the NSNull object.
>
> E.g. when reading the repository info and the description is null on the
> server,
>
> repoInfo.desc = repo[kCMISBrowserJSONRepositoryDescription];
>
>
> repoInfo.desc has the NSNull object instead of nil. Is there a better way
> than to wrap this "dictionary[<key>]” with a helper method?
>
> Something like
>
> + (id)valueOrNil:(id)value
>
> {
>
> return value == [NSNull null] ? nil : value;
>
> }
>
> But then we have to wrap all calls when accessing the value of the dictionary
> with such a method and this would blow up the code.. or do I miss something
> here?
>
>
> The other thing is I need to access the CMISSession within the
> CMISBrowserUtil so that I can retrieve the type definitions (and also make
> use of the type cache) when converting the succinctProperties.
>
> I could add the CMISSession as property to the CMISBrowserBaseService. From
> there I could pass the session to the CMISBrowserUtil. Any objections or even
> a better approach as this seems to me like a dirty workaround?
>
>
> Best regards,
>
> Peter