import java.io. {FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutputStream}
object SymbolSerializeDemo {
def main(args: Array[String]): Unit = {
val fileName = "file.ser"
val symbolCheck: Symbol = Symbol("someSymbol")
//serializeToFile(symbolCheck, fileName)
deserializeFromFile(fileName)
}
private def serializeToFile(input: Symbol, fileName: String): Unit = {
try {
val file: FileOutputStream = new FileOutputStream(fileName)
val out: ObjectOutputStream = new ObjectOutputStream(file)
out.writeObject(input)
}
}
private def deserializeFromFile(fileName: String): Unit = {
try {
val file: FileInputStream = new FileInputStream(fileName)
val input: ObjectInputStream = new ObjectInputStream(file)
val output = input.readObject.asInstanceOf[Symbol]
println("Symbol after deseralization " + output.name)
}
}
}
I am trying to deserialized scala symbol, serialized in scala 2.11 but I am getting error as java.io.InvalidClassException: scala.Symbol; local class incompatible: stream classdesc serialVersionUID = 2966401305346518859, local class serialVersionUID = 6865603221856321286
Can we write custom serialization for this or any other option?
I tried adding serialVersionUID for class as well as for Symbol
I have fixed the issue by downgrading scala version from 2.12.17 to 2.12.6.