There is some code in Mantle, which does that; my look up mechanism will borrow that - but that&#39;s an impl detail<div><br></div><div>The mapper goal is really just to say JSON &quot;key&quot; &#39;blah&#39; is mapped to &#39;foo&#39; on the actual bean (not about the specific types)</div>
<div><br></div><div>Makes sense?</div><div><br></div><div>-M<br><div><div><br><br><div class="gmail_quote">On Fri, Jan 4, 2013 at 2:09 PM, Douglas Campos <span dir="ltr">&lt;<a href="mailto:qmx@qmx.me" target="_blank">qmx@qmx.me</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">how the mapper deals with nested objects?<br>
<div class="HOEnZb"><div class="h5"><br>
On 04/01/2013, at 08:55, Matthias Wessendorf &lt;<a href="mailto:matzew@apache.org">matzew@apache.org</a>&gt; wrote:<br>
<br>
&gt; CoreData: API proposal - AGEntityMapper<br>
&gt; Background<br>
&gt; Mapping JSON representations to a &quot;rich&quot; domain model in ObjC is a bit cumbersome. Similar is true when mapping a JSON data/response to a NSMangedObject (and vise versa). There is a base framework for &quot;remote persistence&quot;, via the CoreData API, by leveraging a custom NSIncrementalStore -&gt; AFIncrementalStore.<br>

&gt;<br>
&gt; For that,... a similar two-way-mapping is required, as described here.<br>
&gt;<br>
&gt; AeroGear and CoreData<br>
&gt; Our CoreData offerings are leveraging the AFIncrementalStore, therefore (as with other frameworks/libraries) we need a mapping as well. We need to know the name of the entity and we need a NSDictionary that covers the actual JSON/property mapping. It could be done with the vanialla ObjC classes:<br>

&gt;<br>
&gt; // some mappers:<br>
&gt; NSDictionary *task_mapper =<br>
&gt;<br>
&gt;<br>
&gt; [NSDictionary dictionaryWithObjectsAndKeys:@&quot;description&quot;,@&quot;desc&quot;,@&quot;id&quot;,@&quot;myId&quot;, nil];<br>
&gt; NSDictionary *project_mapper =<br>
&gt;<br>
&gt;<br>
&gt; [NSDictionary dictionaryWithObjectsAndKeys:@&quot;id&quot;,@&quot;myId&quot;, nil];<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; // create a schema out of the mappers:<br>
&gt; NSDictionary *schema =<br>
&gt;<br>
&gt;<br>
&gt; [NSDictionary dictionaryWithObjectsAndKeys:task_mapper, @&quot;Task&quot;, project_mapper, @&quot;Project&quot;, nil];<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; // pass the schema to the AGCoreDataHelper class, when doing the init...<br>
&gt; Proposal for a custom API<br>
&gt; I&#39;d like to introduce a new wrapper type, called AGEntityMapper:<br>
&gt;<br>
&gt; @interface AGEnityMapper : NSObject<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; @property NSString *name;<br>
&gt; @property NSDictionary *mapper;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; -(id) initWithName:(NSString *) name mapper:(NSDictionary *) mapper;<br>
&gt; @end<br>
&gt; This AGEntityMapper would be applied onto the AGCoreDataConfig:<br>
&gt;<br>
&gt; @protocol AGCoreDataConfig &lt;NSObject&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; @property (strong, nonatomic) NSManagedObjectModel *managedObjectModel;<br>
&gt; @property (strong, nonatomic) NSURL *baseURL;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; -(void)applyEntityMappers:(AGEnityMapper *)firstObject, ... NS_REQUIRES_NIL_TERMINATION;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; @end<br>
&gt; The actual code, would look like this:<br>
&gt;<br>
&gt; EnityMapper *taskMapper =<br>
&gt;<br>
&gt;<br>
&gt; [[EnityMapper alloc] initWithName:@&quot;Task&quot;<br>
&gt;<br>
&gt;<br>
&gt; // mapping the properties on the &quot;entity&quot; (NSManagedObject)<br>
&gt;<br>
&gt;<br>
&gt; // to the external representation (e.g. JSON)<br>
&gt;<br>
&gt;<br>
&gt; mapper:@{ @&quot;desc&quot;: @&quot;description&quot;, @&quot;myId&quot;: @&quot;id&quot;}];<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; EnityMapper *projectMapper =<br>
&gt;<br>
&gt;<br>
&gt; [[EnityMapper alloc] initWithName:@&quot;Project&quot;<br>
&gt;<br>
&gt;<br>
&gt; // mapping the properties on the &quot;entity&quot; (NSManagedObject)<br>
&gt;<br>
&gt;<br>
&gt; // to the external representation (e.g. JSON)<br>
&gt;<br>
&gt;<br>
&gt; mapper:@{ @&quot;myId&quot;: @&quot;id&quot;}];<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; AGCoreDataHelper *helper = [[AGCoreDataHelper alloc] initWithConfig:^(id&lt;AGCoreDataConfig&gt; config) {<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; [config setBaseURL:[NSURL URLWithString:@&quot;<a href="http://server.com" target="_blank">http://server.com</a>&quot;]];<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; [config applyEntityMappers:<br>
&gt;<br>
&gt;<br>
&gt; taskMapper,<br>
&gt;<br>
&gt;<br>
&gt; projectMapper,<br>
&gt;<br>
&gt;<br>
&gt; nil // terminate the varargs.<br>
&gt;<br>
&gt;<br>
&gt; ];<br>
&gt; }];<br>
&gt;<br>
&gt; --<br>
&gt; Matthias Wessendorf<br>
&gt;<br>
&gt; blog: <a href="http://matthiaswessendorf.wordpress.com/" target="_blank">http://matthiaswessendorf.wordpress.com/</a><br>
&gt; sessions: <a href="http://www.slideshare.net/mwessendorf" target="_blank">http://www.slideshare.net/mwessendorf</a><br>
&gt; twitter: <a href="http://twitter.com/mwessendorf" target="_blank">http://twitter.com/mwessendorf</a><br>
</div></div><div class="HOEnZb"><div class="h5">&gt; _______________________________________________<br>
&gt; aerogear-dev mailing list<br>
&gt; <a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><br>
<br>
<br>
_______________________________________________<br>
aerogear-dev mailing list<br>
<a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Matthias Wessendorf <br><br>blog: <a href="http://matthiaswessendorf.wordpress.com/" target="_blank">http://matthiaswessendorf.wordpress.com/</a><br>
sessions: <a href="http://www.slideshare.net/mwessendorf" target="_blank">http://www.slideshare.net/mwessendorf</a><br>twitter: <a href="http://twitter.com/mwessendorf" target="_blank">http://twitter.com/mwessendorf</a>
</div></div></div>