You can implement and shuffle in a tag that disables serialization:
trait NotSerializable extends Serializable {
private def writeObject(out: java.io.ObjectOutputStream): Unit = throw new NotSerializableException()
private def readObject(in: java.io.ObjectInputStream): Unit = throw new NotSerializableException()
private def readObjectNoData(): Unit = throw new NotSerializableException()
}
case class Test(foo: String) extends NotSerializable
The serialization attempt then throws an exception:
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(Test("test"))
|-> java.io.NotSerializableException: A$A39$A$A39
However, what feature of the case class do you really need? The simplest solution might not be to use classes and class objects .
source
share