0

I am contacting a REST service that does not always conform to KVC with RestKit. The response I'm having trouble with is simple:

true

I do not need this value mapped to a class, but this is the class I have set up to receive this value:

@interface BooleanResponse : NSObject
@property (nonatomic) BOOL response;
@end

I have already handled top-level arrays, so I attempted the same mapping:

RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[BooleanResponse class]];
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"response"]];

Upon completion, RestKit prints the error: Loaded an unprocessable response (200) with content type 'application/json'

Interestingly, JSONLint says that true is invalid JSON--but a single boolean response makes sense for this request. (Aside from it being an unnamed value, although as I mentioned KVC is not followed.)

I did not implement the service. Can I make RestKit handle solitary values, or am I stuck handling them as special cases?

31eee384
  • 2,748
  • 2
  • 18
  • 27
  • I guess you have a suitable response descriptor. Does the trace log give more information? – Wain Oct 05 '13 at 18:09
  • It seems to agree with JSONLint that a single value isn't valid JSON. http://pastebin.com/ZMFNMjbz – 31eee384 Oct 05 '13 at 18:13
  • Re: validity, I found [this question](http://stackoverflow.com/q/13318420/382780) that firmly answers that `true` is *NOT* valid JSON. I'm still interested if there's a way to get around this with RestKit, although I'm going to try to get the service changed. – 31eee384 Oct 05 '13 at 18:19
  • 1
    What request are you sending, should you really be using AFNetworking? – Wain Oct 05 '13 at 18:25
  • I am contacting a RESTful service with a request for JSON data. This example is a simple ping GET request, although there will be more complex queries in the future. I'm not familiar with the differences between RestKit and AFNetworking (although I think that RestKit is built on AFNetworking). I think that the object mapping will be useful in this project, though, assuming AFNetworking lacks that. – 31eee384 Oct 05 '13 at 18:34
  • 1
    You have the difference right, but you can use both in the same project where each is most suitable. – Wain Oct 05 '13 at 19:16
  • Hmm, I was hoping to avoid special cases, but if the service can't be changed that sounds like a good solution. (Especially considering I already have AFNetworking in my RestKit build!) – 31eee384 Oct 05 '13 at 19:24

0 Answers0