I see that the restkit document is quite nice and has variety of examples on object modelling. There is also an example of nested mapping but I find my scenario little bit different than this. RestKit documentation provides the example mapping of the nested attribute with the following json format.
Sample JSON structure from the RestKit Documentation :
{
"blake": {
"email": "blake@restkit.org",
"favorite_animal": "Monkey"
},
"sarah": {
"email": "sarah@restkit.org",
"favorite_animal": "Cat"
}
}
Suppose that my json is a bit different as this;
My JSON structure :
{
"id" : 1,
"author" : "RestKit",
"blake": {
"email": "blake@restkit.org",
"favorite_animal": "Monkey"
},
"sarah": {
"email": "sarah@restkit.org",
"favorite_animal": "Cat"
}
}
I created two different managedobject model with the following attributes and to many relations.
Two different entities for my structure Product and creator to map the above JSON object.
Product Creator
identifier <------------------- >> name
author email
favouriteAnimal
Now, my mapping would look like this for Product model would be;
This is how I map the Product entity, [mapping mapKeyPath:"id" toAttribute:"identifier"]; [mapping mapKeyPath:"author" toAttribute: "author"];
But note here, mapping the nested dictionary attribute does not work for me. // [mapping mapKeyOfNestedDictionaryToAttribute:@"creators"];
Now, in the authors class.
I could not figure out the usual way to map the above JSON structure.