I am trying to post a contents of an entity(Articles) and its relationship(Authors) with Restkit object mapping.
Articles <->> Authors An article can have many authors.
My current object mapping is as below,
RKObjectMapping *authorMapping = [RKObjectMapping requestMapping];
[authorMapping addAttributeMappingsFromArray:@[@"name",@"email"]];
RKObjectMapping *articleMapping = [RKObjectMapping requestMapping];
[articleMapping addAttributeMappingsFromArray:@[@"title",@"body",@"date"]];
RKRelationshipMapping * rel =[RKRelationshipMapping relationshipMappingFromKeyPath:@"author" toKeyPath:@"author" withMapping:authorMapping];
[articleMapping addPropertyMapping:rel];
RKObjectMapping *mapping = [RKObjectMapping requestMapping];
[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"singleArticle" toKeyPath:@"singleArticle" withMapping:articleMapping]];
For this mapping I was expecting a JSON output with an array of authors as below,
{
"singleArticle": {
"author": [
{
"email": "dadsa@",
"name": "rk"
},
{
"email": "3ldll",
"name": "rjk"
}
],
"body": "body content",
"date": "2014-05-16T15:54:40Z",
"title": "some title"
}
}
But the generated JSON Output turns out with all the fields in the author class as a separate object as below,
{
"singleArticle": {
"author": [
{
"email": "dadsa@"
},
{
"name": "rk"
},
{
"email": "3ldll"
},
{
"name": "rjk"
}
],
"body": "body content",
"date": "2014-05-16T15:54:40Z",
"title": "some title"
}
}
I am not sure how what I am missing here that messes up the JSON feed as above. Any thoughts to produce a proper JSON with an array of author objects?