RestKit , PUT complex JSON to server -
the request json want set server
"type": "payment", "paymentoptions": [ { "type": "netbanking", "name": "netbanking - axis bank", "expirydate": null, "bank": "axis bank" } ]
class mapping
@interface ctspaymentdetailupdate : nsobject @property(nonatomic, strong, readonly) nsstring* type; @property(nonatomic, strong, readonly) nsmutablearray* paymentoptions; @interface ctspaymentoption : nsobject @property(nonatomic, strong) nsstring* type, *ownername, *number, *bankname, *expirydate;
code mapping
#define mlc_profile_update_payment_request_mapping \ @{ \ @"type" : @"type", \ @"bank" : @"bankname", \ @"owner" : @"ownername", \ @"number" : @"number", \ @"expirydate" : @"expirydate", \ @"name" : @"cardname" \ } rkobjectmapping* paymentoptionmapping = [rkobjectmapping mappingforclass:[ctspaymentoption class]]; [paymentoptionmapping addattributemappingsfromdictionary: mlc_profile_update_payment_request_mapping]; rkobjectmapping* paymentdetailreq = [rkobjectmapping requestmapping]; [paymentdetailreq addattributemappingsfromdictionary:@{ @"type" : @"type" }]; [paymentdetailreq addpropertymapping: [rkrelationshipmapping relationshipmappingfromkeypath:@"paymentoptions" tokeypath:@"paymentoptions" withmapping:paymentoptionmapping]]; rkrequestdescriptor* requestdes = [rkrequestdescriptor requestdescriptorwithmapping:paymentdetailreq objectclass:[ctspaymentdetailupdate class] rootkeypath:nil method:[self gethttpmethodfor:put]]; [objectmanager addrequestdescriptor:requestdes];
once utilize next set object server
[objectmanager putobject:object path:path parameters:queryparams success:^(rkobjectrequestoperation* operation, rkmappingresult* mappingresult) { //code } failure:^(rkobjectrequestoperation* operation, nserror* error) { //code }];
i nsunknownkeyexception on line 2014-06-22 11:12:22.587 restfulltester[1727:60b] *** terminating app due uncaught exception 'nsunknownkeyexception', reason: '[<ctspaymentoption 0x10bf2ae80> valueforundefinedkey:]: class not key value coding-compliant key owner.'
i think there wrong the way have made mapping not able understand,also there way test json code produce beforehand
this line:
withmapping:paymentoptionmapping]];
when creating relationship mapping should be:
withmapping:[paymentoptionmapping inversemapping]]];
json restkit restkit-0.20
No comments:
Post a Comment