-
Notifications
You must be signed in to change notification settings - Fork 61
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
Comments
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. |
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 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 |
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! |
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. |
Hello, First, thank you for Groot, it's an amazing tool ! |
No update, sorry. I’m open to suggestions and pull requests 😀. |
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
The text was updated successfully, but these errors were encountered: