Friday, 27 March 2015

Restkit swift issue and solutions




1, you may have this issue when you want to parse the response of a query:

Adding mapping error: Expected an object mapping for class of type 'aa', provider returned one for 'bb'
the reason is: you use one object(and mapping) for query or posting, but you want to use another object(and mapping) for response. because by default, restkit will use the same object(mapping) for response.

According to the documentation of restkit you should set "operation.targetobject=nil":
http://stackoverflow.com/questions/13921936/restkit-response-cant-be-deserialzed-to-object

However, if you use "postobject()" you have no chance to get this "operation" object.

My solution is : add properties to you model to handle the response message, I know it is ugly, but no better solutions.



2, you may have this issue if you want to handle 400 response of a GET request:


(400 Bad Request / 0 objects) [request=0.0000s mapping=0.0000s total=0.0732s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No mappable object representations were found at the key paths searched." UserInfo=0x7f832e108d60 {NSLocalizedDescription=No mappable object representations were found at the key paths searched., NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: 
The representation inputted to the mapper was found to contain nested object representations at the following key paths: status, storeCollections-shipment
This likely indicates that you have misconfigured the key paths for your mappings., keyPath=null, DetailedErrors=(

)}

The reason is your "pathpattern" is wrong.  if you have a path like this:

/vi/api/abc/:v1?aaa=v2&bbb=v3

then your "pathpattern" should be "/vi/api/abc/:xxx"

you should use :/xxx replace the hole path.








No comments:

Post a comment