Hi Guys.
I'm playing with serialisation, and hitting an issue with typing when reading back in from a file.
My current plan of action is to use a filename prefix to suggest the correct type, then base the deserialisation on that type. (This may well be a "Very Bad Idea", so any suggestions otherwise would be most gratefully received!)
Essentially, I want to write an object to a file, then, at some point later, read the file back in to an object of the correct type.
The following is something like what I want to use:
def readPatch(name:String): Patch = {
// split name at tilde, prefix gives type
val List(typeCode, filename) = List.fromString(name,'~')
val patchClass = typeCode match {
case "cfp" => CreateFilePatch.getClass
case "dfp" => DeleteFilePatch.getClass
case "cp" => ChangePatch.getClass
}
val inStream = new ObjectInputStream(new FileInputStream(filename))
inStream.readObject().asInstanceOf[patchClass]
}
but I think am not able to due to Types not being Objects. I'm getting an error of "not found: type patchClass" when trying this code.
Could anyone suggest ideas?