We're currently evaluating JSONModel for our iOS app and are liking it very much so far. The thing is, we have to deal with an OData API which tends to overcomplicate things in a couple of places. For instance, when getting back a list of entities, all APIs I can think of return something simple like this:
{
items: [
{ id => 123, name => 'foo' },
{ id => 124, name => 'bar' },
{ id => 125, name => 'baz' },
]
}
Unfortunately, OData gives me something more like this:
{
d: {
results: [
{ Item => { id => 123, name => 'foo' } },
{ Item => { id => 124, name => 'bar' } },
{ Item => { id => 125, name => 'baz' } },
]
}
}
The "d" being my least problem (as we can just parse it away). But I can't figure out how to cope with the fact that every item in the list is wrapped in a hash with the item's type as the key, so that a JSONModel relationship via NSArray does not work. I could probably define JSONKeyMapper for my Item like this:
@"Item.id" : @"id",
@"Item.name" : @"name"
but the OData standard only wraps items in their own hash structure when there are multiple items. For instance, when fetching just a single item from the OData API, I get (as expected):
{
d: {
results: {
id => 123,
name => 'foo'
}
}
}
:-(
Any ideas on how to deal with this? And before anyone suggests one of the two major OData iOS clients out there: Unfortunately, they both seem to be rather unsupported and/or outdated, including the official one listed by Microsoft.