As already mentioned, you can define your own writeObject and readObject methods.
@throws(classOf[java.io.IOException]) private def writeObject(out : java.io.ObjectOutputStream) : Unit =
However, be careful when doing this on nested classes, objects, or traits.
@serializable class Foo (x: Int) {@serializable object X {def y = x}}
If I serialize an X object, it actually serializes the containing class Foo, so it must also be serializable. It could be PITA to deal with the usual serialization methods, so here is a fair warning.
Another point of pain may be serialization closure. Try to maintain a mental model of which variables are captured in serialized closures. Make sure these variables are what you want to send via IO!
jsuereth
source share