0
votes

I have a JSON object that I would like to map into two core data objects with a relationship between the two.

For example, if the JSON is:

{
 "name"    : "tom",
 "company" : "ACME",
 "phone"   : "123-456-7890",
 "email"   : "[email protected]",
 "height"  : "60",
 "weight"  : "172"
}

I would like to parse the JSON object into a Person object that contains the "name" field. The person object would then have a relationship to a contactInfo object that contains the "email" and "phone" field, and another relationship to a bodyStats object that contains the "height" and weight "field". What is the best way to do this? I fairly proficient with normal RestKit mapping but this one has stumped me, can I achieve this with dynamic mapping? Do I have to use key validation and custom map objects?

Thanks for your help!

1
Do you need to parse the JSON objects and then create CoreData entities? - Puneet Sharma

1 Answers

0
votes

Set up 3 different response descriptors, linked to your 3 model classes. Each response descriptor should specify the same path pattern and keypath (if the JSON isn't nested as per your question then use a nil key path).

The key is to use foreign key mapping, based on the name. This means adding transient attributes to the contact and stats entities and configuring their mappings to connect the relationship to the person entity with the specified name.