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

Prevent infinite recursion when Groot traverses complex data model? #83

Open
dhearst opened this issue Aug 22, 2017 · 6 comments
Open

Comments

@dhearst
Copy link

dhearst commented Aug 22, 2017

Hi,

We're trying to use Groot to serialize and deserialize our main data object class. It is a complex managed object with many relationships. In turn, many of its related objects are related to each other and to other nested objects. That means that there are 10-15 entities that are intertwined with forward and reverse relationships.

I've started testing Groot with our real-world data and immediately encountered a crash because Groot was recursing infinitely amidst our intertwined relationships. I have been able to prevent that by removing the JSONKeyPath user info on a few reverse relationships. This makes me wonder if I'm missing something in the way we've adopted Groot. I do have identityAttributes on all of our entities (applied to the entities themselves...is that correct?) Is there something else needed to convince Groot to stop parsing the object hierarchy when it reaches objects that were already parsed previously?

Thanks for any suggestions you can give me...Groot is amazing and we're really hoping to get it fully functional in our app. :)

David

@dhearst dhearst changed the title Prevent infinite recursion when Groot traverse complex data model? Prevent infinite recursion when Groot traverses complex data model? Aug 22, 2017
@gonzalezreal
Copy link
Owner

Hi @dhearst,

In general, you should avoid trying to parse reverse relationships in the JSON. So removing the JSONKeyPath from entities in the right side of a relationship is a good idea.

Could you provide a sample of the JSON that is giving you trouble? Maybe I can help.

@dhearst
Copy link
Author

dhearst commented Aug 23, 2017

Right now I'm trying to generate JSON from Core Data objects, so I have yet to generate the desired JSON output. From stepping through Groot with our data, I'm pretty sure our problems occur because of cyclic relationships, e.g.

A relates to B
B relates to C
C relates to A

As I step through the JSON-generation code, it appears that this leads to Groot repeatedly cycling through A, then B, then C, then back to A and eventually the app dies because of the depth of the recursion.

Is there a way to use Groot successfully in the presence of cyclic relationships like this? Ideally, we'd be able to parse only the unique objects in the data, skipping any relationship that points to an object previously parsed.

Or, is it better to leave off JSONKeyPath assignments for some/all of the potentially cyclic relationships and somehow recognize that they need to be reconnected after parsing the JSON to create objects?

Thanks, David

@gonzalezreal
Copy link
Owner

I am afraid Groot is not ready to work properly in the situation you are describing. As soon as I have a free slot available I will have a look and try to find a solution. Thanks for the feedback!

@dhearst
Copy link
Author

dhearst commented Aug 30, 2017

OK, I've made some headway by being careful about which forward and/or reverse relationships have JSONParseKeys but I do think that we have a few cases where current Groot functionality may not be enough. I'm happy to provide details as needed if you get to the point where you are looking at this closely...I can do legwork or help out...just let me know. Thanks.

@aymericbaur
Copy link

Hello,

First, thank you for Groot, it's an amazing tool !
Unfortunately I am falling in the same recursive trap mentioned above.
Is there a chance that you have any update on this problem ?

@gonzalezreal
Copy link
Owner

No update, sorry. I’m open to suggestions and pull requests 😀.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants