did a quick update on the gist:<div><br></div><div><a href="https://gist.github.com/843c89668b2216929633">https://gist.github.com/843c89668b2216929633</a></div><div><br></div><div>;-)</div><div><br></div><div><br><br><div class="gmail_quote">
On Fri, Jan 4, 2013 at 4:08 PM, Matthias Wessendorf <span dir="ltr"><<a href="mailto:matzew@apache.org" target="_blank">matzew@apache.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
that's the idea<div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">On Fri, Jan 4, 2013 at 3:07 PM, Douglas Campos <span dir="ltr"><<a href="mailto:qmx@qmx.me" target="_blank">qmx@qmx.me</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Ah so the mapping is reversed then?<br>
<div><div><br>
On 04/01/2013, at 11:16, Matthias Wessendorf <<a href="mailto:matzew@apache.org" target="_blank">matzew@apache.org</a>> wrote:<br>
<br>
> There is some code in Mantle, which does that; my look up mechanism will borrow that - but that's an impl detail<br>
><br>
> The mapper goal is really just to say JSON "key" 'blah' is mapped to 'foo' on the actual bean (not about the specific types)<br>
><br>
> Makes sense?<br>
><br>
> -M<br>
><br>
><br>
> On Fri, Jan 4, 2013 at 2:09 PM, Douglas Campos <<a href="mailto:qmx@qmx.me" target="_blank">qmx@qmx.me</a>> wrote:<br>
> how the mapper deals with nested objects?<br>
><br>
> On 04/01/2013, at 08:55, Matthias Wessendorf <<a href="mailto:matzew@apache.org" target="_blank">matzew@apache.org</a>> wrote:<br>
><br>
> > CoreData: API proposal - AGEntityMapper<br>
> > Background<br>
> > Mapping JSON representations to a "rich" 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 "remote persistence", via the CoreData API, by leveraging a custom NSIncrementalStore -> AFIncrementalStore.<br>
> ><br>
> > For that,... a similar two-way-mapping is required, as described here.<br>
> ><br>
> > AeroGear and CoreData<br>
> > 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>
> ><br>
> > // some mappers:<br>
> > NSDictionary *task_mapper =<br>
> ><br>
> ><br>
> > [NSDictionary dictionaryWithObjectsAndKeys:@"description",@"desc",@"id",@"myId", nil];<br>
> > NSDictionary *project_mapper =<br>
> ><br>
> ><br>
> > [NSDictionary dictionaryWithObjectsAndKeys:@"id",@"myId", nil];<br>
> ><br>
> ><br>
> ><br>
> > // create a schema out of the mappers:<br>
> > NSDictionary *schema =<br>
> ><br>
> ><br>
> > [NSDictionary dictionaryWithObjectsAndKeys:task_mapper, @"Task", project_mapper, @"Project", nil];<br>
> ><br>
> ><br>
> ><br>
> > // pass the schema to the AGCoreDataHelper class, when doing the init...<br>
> > Proposal for a custom API<br>
> > I'd like to introduce a new wrapper type, called AGEntityMapper:<br>
> ><br>
> > @interface AGEnityMapper : NSObject<br>
> ><br>
> ><br>
> ><br>
> > @property NSString *name;<br>
> > @property NSDictionary *mapper;<br>
> ><br>
> ><br>
> ><br>
> > -(id) initWithName:(NSString *) name mapper:(NSDictionary *) mapper;<br>
> > @end<br>
> > This AGEntityMapper would be applied onto the AGCoreDataConfig:<br>
> ><br>
> > @protocol AGCoreDataConfig <NSObject><br>
> ><br>
> ><br>
> ><br>
> > @property (strong, nonatomic) NSManagedObjectModel *managedObjectModel;<br>
> > @property (strong, nonatomic) NSURL *baseURL;<br>
> ><br>
> ><br>
> ><br>
> > -(void)applyEntityMappers:(AGEnityMapper *)firstObject, ... NS_REQUIRES_NIL_TERMINATION;<br>
> ><br>
> ><br>
> ><br>
> > @end<br>
> > The actual code, would look like this:<br>
> ><br>
> > EnityMapper *taskMapper =<br>
> ><br>
> ><br>
> > [[EnityMapper alloc] initWithName:@"Task"<br>
> ><br>
> ><br>
> > // mapping the properties on the "entity" (NSManagedObject)<br>
> ><br>
> ><br>
> > // to the external representation (e.g. JSON)<br>
> ><br>
> ><br>
> > mapper:@{ @"desc": @"description", @"myId": @"id"}];<br>
> ><br>
> ><br>
> ><br>
> > EnityMapper *projectMapper =<br>
> ><br>
> ><br>
> > [[EnityMapper alloc] initWithName:@"Project"<br>
> ><br>
> ><br>
> > // mapping the properties on the "entity" (NSManagedObject)<br>
> ><br>
> ><br>
> > // to the external representation (e.g. JSON)<br>
> ><br>
> ><br>
> > mapper:@{ @"myId": @"id"}];<br>
> ><br>
> ><br>
> ><br>
> > AGCoreDataHelper *helper = [[AGCoreDataHelper alloc] initWithConfig:^(id<AGCoreDataConfig> config) {<br>
> ><br>
> ><br>
> ><br>
> > [config setBaseURL:[NSURL URLWithString:@"<a href="http://server.com" target="_blank">http://server.com</a>"]];<br>
> ><br>
> ><br>
> ><br>
> > [config applyEntityMappers:<br>
> ><br>
> ><br>
> > taskMapper,<br>
> ><br>
> ><br>
> > projectMapper,<br>
> ><br>
> ><br>
> > nil // terminate the varargs.<br>
> ><br>
> ><br>
> > ];<br>
> > }];<br>
> ><br>
> > --<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><br>
> > _______________________________________________<br>
> > aerogear-dev mailing list<br>
> > <a href="mailto:aerogear-dev@lists.jboss.org" target="_blank">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>
><br>
><br>
> _______________________________________________<br>
> aerogear-dev mailing list<br>
> <a href="mailto:aerogear-dev@lists.jboss.org" target="_blank">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>
><br>
><br>
><br>
> --<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><br>
> _______________________________________________<br>
> aerogear-dev mailing list<br>
> <a href="mailto:aerogear-dev@lists.jboss.org" target="_blank">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>
<br>
<br>
_______________________________________________<br>
aerogear-dev mailing list<br>
<a href="mailto:aerogear-dev@lists.jboss.org" target="_blank">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></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>