Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restkit Response in text/xml

I have a WS that return a plist.
I am using Restkit and I would like to map the response.

So first I initilialize my ObjectManager like this:

sharedInstance.manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:ROOT_URL]];

I accept the text/xml:

[[RKObjectManager sharedManager] setAcceptHeaderWithMIMEType:RKMIMETypeTextXML];

And I launch my request:

NSMutableURLRequest *request = [[RKObjectManager sharedManager] requestWithObject:nil method:RKRequestMethodPOST path:@"/foo/foo" parameters:nil];
RKManagedObjectRequestOperation *operation = [[RKObjectManager sharedManager] managedObjectRequestOperationWithRequest:request managedObjectContext:[BddManager sharedInstance].manager.managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
    NSLog(@"Loading mapping result: %d", result.count);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    NSLog(@"Fail!");
}];
[operation start];

Finally I get this error:

NSLocalizedDescription=Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/xml, 

What am I doing wrong?

like image 905
Alexis.J Avatar asked Dec 27 '22 09:12

Alexis.J


1 Answers

RestKit 0.20.0rc1 does not include an XML serializer in the main repository, but you can find one here: RKXMLReaderSerialization.

Install via cocoapods: (or add the source files to your project)

pod 'RKXMLReaderSerialization', :git => 'https://github.com/RestKit/RKXMLReaderSerialization.git', :branch => 'master'

Import the header where you initialize RestKit.

#import "RKXMLReaderSerialization.h"

Finally, register the serialization class with RestKit. Insert this after you initialize the object manager and before you set the accept header.

sharedInstance.manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:ROOT_URL]];
[RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:@"application/xml"];
[[RKObjectManager sharedManager] setAcceptHeaderWithMIMEType:RKMIMETypeTextXML];
like image 52
Jon Avatar answered Jan 28 '23 09:01

Jon