Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Mapping Entity Based on Internal Data #105

Closed
blakewatters opened this issue May 13, 2011 · 5 comments
Closed

Support for Mapping Entity Based on Internal Data #105

blakewatters opened this issue May 13, 2011 · 5 comments
Assignees
Milestone

Comments

@blakewatters
Copy link
Member

Hi,

I need to have a mapping from JSON to my entities that is a bit more
complex than the default mapping that maps from the JSON outer key to
an entity.

There are two different cases of the problem

1- The API returns a payload with a JSON type of "Result" for many
different queries. The content of the "Result" structure is totally
unrelated to any other, only to the initial query. How could I handle
such a mapping?

2- Sometimes the payload I get under the same JSON type differs
depending on one inner field, usually called xxxKind. Here is a
contrived example:

{"Results":[
   { "Person": { "Name": "John", "Sex": "M"}},
   { "Person": { "Name": "Jane", "Sex": "F"}}
]}

And here I would like to instanciate John as a "Man" entity, and
"Jane" as a "Woman" entity.
Most probably, "Man" and "Woman" would be subentities of an abstract
"Person" entity.

How could I handle such a mapping?

I think it would be enough if I had a delegate method that would look
into the parsed directory from the JSON parser in order to decide and
return the name of the entity to instanciate,

Or something along those lines.

Thanks for any suggestion...
@SaschaKonietzke
Copy link

Currently investigating if we can use RestKit and already saw this on the mailing list. We have the same requirement and it would be great to see this included.

+1

@ghost ghost assigned blakewatters Jun 16, 2011
@blakewatters
Copy link
Member Author

Moving to 0.9.4

@houseoflegend
Copy link

Hey Blake! Saw the forum post on this one and looked it up here. +1 for as well.

An example of our use case might be more like this:
{"Person" : {"Name: "John", ...}}
maps to Person abstract entity in Core Data

{"Person": { "Name": "John", "tools": {"Hammer", "Screwdriver", "Drill"}}}
maps to Carpenter class, which has Person abstract entity as its Parent Entity.

{"Person": { "Name": "John", "specialty_dish": "Lasagna"}}
maps to Chef class, which also has Person abstract entity as its Parent Entity.

@blakewatters
Copy link
Member Author

Alright, I am reopening this on 0.9.3 as the final task for the release. It's in the core of the object mapper and I want to focus primarily on Core Data in 0.9.4, so let's knock out the design vetted in #244

@houseoflegend
Copy link

Terrific, thanks for the update Blake!

blakewatters added a commit that referenced this issue Jul 30, 2011
…rt for polymorphic relationship mapping. refs #105
blakewatters added a commit that referenced this issue Jul 30, 2011
…nately introduces some API turbulence, but the support is now first class. refs #105
blakewatters added a commit that referenced this issue Jul 30, 2011
…s enables you to dynamically map objects to different destination classes or using different mapping strategies via configuration or callbacks. See Docs/Object Mapping.md for details.

Other changes include:
* Eliminated the RKObjectFactory protocol and implementations. Object mapping instances themselves are
now responsible for instantiating target objects for mapping.
* Introduced RKObjectAbstractMapping superclass for RKObjectMapping and RKObjectPolymorphicMapping.
* Updated example applications to use block object loaders (RKTwitter and RKTwitterCoreData)
* Refactored method signatures of RKObjectMapper, RKObjectMapping, and RKObjectMappingProvider to reflect the
existence of abstract mapping types. This was necessary to make polymorphic mappings integrate cleanly.
* Fixed overlap in RestKit error domains between network and object mapping. fixes #208
blakewatters added a commit that referenced this issue Jul 31, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants