The backstory:
I have a Location class for room objects. It contains an ArrayList for exits.
I have an Exit class for exits from locations, which store the direction of the exit and where it leads to.
I add exits like so:
p1.addExit(new Exit(Exit.NORTH, p2));
p2.addExit(new Exit(Exit.SOUTH, p1));
I serialize all of this information and save it in my save/load process. This all worked fine in a proof-of-concept with 5 locations.
The problem:
I actually have about 40 connected locations now, and get a stackoverflow on save/load because of all the connections.
I think the best way to deal with this at the moment would be to limit the recursion in the serialization. I cannot mark the exits transient because in the course of the game, they are added and removed. There are many variables that get changed for each location, so saving everything about them is the optimal solution, rather than doing a bunch of broken up saving/loading of individual object variables.
I have found several posts here on SO indicating that writing your own writeObject and readObject custom serialization handling is the best option to control the recursion. However, I freely admit I'm too much of a novice to know how to do this, and I have been unable to find any examples on limiting recursion that don't also involve the use of plugins that I'm not using.
Any guidance here would be greatly appreciated.
EDIT: This is not a dupe of the suggested dupe. I don't need help pinpointing the source of my stack overflow; I know what's causing it.