Last active
February 26, 2025 11:43
Revisions
-
ramn revised this gist
May 14, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,7 @@ class Animal(name: String, age: Int) extends Serializable { case class Person(name: String) // or fork := true in sbt class ObjectInputStreamWithCustomClassLoader( fileInputStream: FileInputStream ) extends ObjectInputStream(fileInputStream) { -
ramn revised this gist
May 13, 2013 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,18 @@ class Animal(name: String, age: Int) extends Serializable { case class Person(name: String) class ObjectInputStreamWithCustomClassLoader( fileInputStream: FileInputStream ) extends ObjectInputStream(fileInputStream) { override def resolveClass(desc: java.io.ObjectStreamClass): Class[_] = { try { Class.forName(desc.getName, false, getClass.getClassLoader) } catch { case ex: ClassNotFoundException => super.resolveClass(desc) } } } object MyDeserialize extends App { val fis = new FileInputStream("../a.tmp") val ois = new ObjectInputStreamWithCustomClassLoader(fis) val animal = ois.readObject val person = ois.readObject -
ramn created this gist
May 13, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ import java.io._ @SerialVersionUID(15L) class Animal(name: String, age: Int) extends Serializable { override def toString = s"Animal($name, $age)" } case class Person(name: String) object MyDeserialize extends App { val fis = new FileInputStream("../a.tmp") val ois = new ObjectInputStream(fis) val animal = ois.readObject val person = ois.readObject ois.close println(animal) println(person) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ import java.io.FileOutputStream import java.io.ObjectOutputStream @SerialVersionUID(15L) class Animal(name: String, age: Int) extends Serializable { override def toString = s"Animal($name, $age)" } case class Person(name: String) extends Serializable object MySerialize extends App { val fos = new FileOutputStream("../a.tmp") val oos = new ObjectOutputStream(fos) oos.writeObject(new Animal("Dvorak", 12)) oos.writeObject(Person("Dijkstra")) oos.close }