From 4be5e11cccace4974ed9a449052455392570139f Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Tue, 30 Nov 2010 15:38:56 +0000 Subject: Deprecated the @serializable annotation, introd... Deprecated the @serializable annotation, introduce a new trait "scala.Serializable" which has to be extended instead (cross-platform). Known issues: - Companion objects of serializable classes (including case classes) are automatically made serializable. However, they don't extend "Serializable" statically because of the known difficulty (should be done before typing, but hard). - Writing "case class C() extends Serializable" gives "error: trait Serializable is inherited twice" - Functions are serializable, but don't extend Serializable dynamically (could be fixed by making FunctionN Serializable - shouldn't we?) Note that @SerialVersionUID continues to be an annotation; it generates a static field, which is not possible otherwise in scala. Review by dragos, extempore. Question to dragos: in JavaPlatform.isMaybeBoxed, why is there a test for "JavaSerializableClass"? Is that correct? --- test/files/jvm/serialization.scala | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'test/files/jvm') diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala index b16d46adad..2e34079505 100644 --- a/test/files/jvm/serialization.scala +++ b/test/files/jvm/serialization.scala @@ -40,7 +40,6 @@ object Test1_scala { (a1.length == a2.length) && (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }) - @serializable object WeekDay extends Enumeration { type WeekDay = Value val Monday, Tuesday, Wednesday, Thusday, Friday, Saturday, Sunday = Value @@ -187,7 +186,6 @@ object Test1_scala { //############################################################################ // Test classes in package "scala.collection.immutable" -@serializable object Test2_immutable { import scala.collection.immutable.{ BitSet, HashMap, HashSet, ListMap, ListSet, Queue, Range, SortedMap, @@ -353,10 +351,6 @@ object Test3_mutable { val _hs1: HashSet[String] = read(write(hs1)) check(hs1, _hs1) - // History - @serializable - class Feed extends Publisher[String] - val h1 = new History[String, Int] val _h1: History[String, Int] = read(write(h1)) check(h1, _h1) @@ -373,8 +367,6 @@ object Test3_mutable { val _lb1: ListBuffer[String] = read(write(lb1)) check(lb1, _lb1) - // Publisher - // Queue val q1 = new Queue[Int] q1 ++= List(20, 2, 3).iterator @@ -471,8 +463,7 @@ object Test4_xml { //############################################################################ // Test user-defined classes WITHOUT nesting -@serializable -class Person(_name: String) { +class Person(_name: String) extends Serializable { private var name = _name override def toString() = name override def equals(that: Any): Boolean = @@ -480,12 +471,11 @@ class Person(_name: String) { (name == that.asInstanceOf[Person].name) } -@serializable -class Employee(_name: String) { +class Employee(_name: String) extends Serializable { private var name = _name override def toString() = name } -@serializable + object bob extends Employee("Bob") object Test5 { @@ -508,13 +498,10 @@ object Test5 { //############################################################################ // Test user-defined classes WITH nesting -@serializable object Test6 { - @serializable object bill extends Employee("Bill") { val x = paul } - @serializable object paul extends Person("Paul") { val x = 4 // bill; => StackOverflowException !!! } @@ -540,11 +527,8 @@ object Test6 { //############################################################################ // Nested objects cannot get readresolve automatically because after deserialization // they would be null (they are treated as lazy vals) -@serializable -class Outer { - - @serializable - object Inner +class Outer extends Serializable { + object Inner extends Serializable } object Test7 { @@ -564,11 +548,10 @@ object Test7 { // Verify that transient lazy vals don't get serialized -@serializable -class WithTransient { +class WithTransient extends Serializable { @transient lazy val a1 = 1 @transient private lazy val a2 = 2 - @transient @serializable object B + @transient object B extends Serializable def test = { println(a1) -- cgit v1.2.3