Search code examples
javaserializationobjectstack-overflowbuffering

Java : Writing an object to a file avoiding java.lang.StackOverflowError


I want to write some large amount of data to a file. the data is contained in an object. object is implemented as serializable. The thing is when I try to write it to a file using ObjectOutputStream's writeObject, it gives the StackOverflowError because the size of the object is large.

I only need to save the object so that i can open and use it again, change some values, and save to disk again.

The object file is a NeuralNetwork created with Neuroph framework, so i dont like to look into its big code and pick data one by one and serialize the stuff.

Please can someone suggest a way to slice the object ( or some buffering effect ) and save at least. i think that kind of thing would do the trick.

Thank you. :)


Solution

  • Can you consider increasing the stack size (-Xss2m or so) as maybe just having more on the stack will allow you to get it done?

    Beyond that there is not really a way to cut up an object graph for serialization (without understanding the objects).