I'm fairly new to Restkit but so far its worked pretty well for me using version 0.20.3 for most of my networking needs.
Im consuming a json based API written in c# using WCF webhttp bindings, it is worth mentioning at this point that I have absolutely no control of this API and cannot change the format of the returned json and I need to work with what I have.
The problem is that when the API returns a simple type like int, double or string as the response the json response is completely bare as below..
string response
"hello world"
int response
2342524
Both of these example responses have a content type of application/json
Ive tried to consume an API endpoint with restkit that gets a count of customer orders by the customer number. The code for the request is as follows and Im expecting an NSNumber as the response but its generating an error as its a raw unwrapped type and I cant provide a mapping for this.
[manager getObject:nil
path:@"/service/http/CountOrders?CustomerId=324534413"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){
RKLogInfo(@"order count: %@",mappingResult);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(@"Operation failed with error: %@", error);
}];
And the error I'm getting back is
restkit.network:RKResponseMapperOperation.m:317 Failed to parse response data: Loaded an unprocessable response (200) with content type 'application/json'
restkit.network:RKObjectRequestOperation.m:213 GET 'http://CUSTOMERDOMAIN/service/http/CountOrders?CustomerId=324534413'
(200 OK / 0 objects)
[request=0.2263s mapping=0.0000s total=0.2386s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1017 "Loaded an unprocessable response (200) with content type 'application/json'"
UserInfo=0x8e1a660 {NSErrorFailingURLKey=http://CUSTOMERDOMAIN/service/http/CountOrders?CustomerId=324534413, NSUnderlyingError=0x8e1b1a0
"The operation couldn’t be completed. (Cocoa error 3840.)",
NSLocalizedDescription=Loaded an unprocessable response (200) with content type 'application/json'}
hj
Is there any way of parsing the the response to an NSNumber to cover this edge case? Im thinking a custom deserialization handler might be the way to go if thats at all possible but as I said I'm new to restkit and am basically looking for a push in the right direction.