I am working with the following complicated object:
ObjectA {
somearr: [
ObjectB {
somevar: ObjectD {...},
somecircularvar: pointer
},
ObjectC {...},
...
],
someobj: ObjectE {
someothercircularvar: pointer,
somevar: ObjectF {...}
},
someMethod: ...
}
The above object has the following:
- Nested objects
- Circular references to many locations within the object (not just the main reference)
- User-defined objects
Main Question: How do I turn this object into a string for storage, and how do I parse the string back into the object with all of the methods and variables as is?
Things I have Tried:
- Libraries
- Flatted.js
- Cyro.js
- JSONfn.js
- Searches
- Existing Stack Overflow Questions (none seemed to deal with my monstrosity)
- Google searching serialization of user-defined objects (these could not deal with circular)
After trying these I saw that all of the "solutions" deal with circular and nested objects, not user-defined objects.
I do remember trying a couple other libraries but none could deal with circular, nested, and user-defined objects all at the same time.
The closest I have gotten to is the following parse:
{
somearr: [
{
somevar: {...},
somecircularvar: pointer
},
{...},
...
],
someobj: {
someothercircularvar: pointer, // Circular pointer conserved
somevar: {...}
}
}
Notice how my object names have disappeared, and each __proto__ is now the default object (not my object as defined by my local classes) with none of my methods conserved.
Huge thanks in advance to the person that can solve this problem.