Search code examples
restkitrestkit-0.20

is RestKit has default mapping if omit some field


my json and object both contain some fields with same name, and my mapping like this:

[mapping addAttributeMappingsFromArray :@[ @"postId", @"fieldname1", @"fieldname2", @"fieldname3", @"fieldname4", @"fieldname5"]];

if json was returned without fieldname4, it is fine, the mapping just ignore it.

but on the contrary, if I forget some field in mapping, for example.

[mapping addAttributeMappingsFromArray :@[ @"postId"]];

then the object will got nothing except postId even if json contains every field.

is there someway I can tell the mapping to do some "default mapping" if json and object contained same field name. So I need not list all the field names to the mapping even if their field names are all same.


Solution

  • No. You explicitly list the keys which should be processed.

    You could create a dynamic mapping which introspects on the response and the destination object and creates a mapping including all keys. RestKit doesn't do that because it's slow...