Skip to content

Commit f72d01a

Browse files
committed
Weirdness in serialization
0 parents  commit f72d01a

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

build.sbt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name := "minimized-list-serialization"
2+
3+
scalaVersion := "2.10.5"
4+
5+
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.4"
6+
7+
//fork in Test := true

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=0.13.8-RC1

src/main/scala/issue/Issue.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package issue
2+
3+
case class Meh(s: String)
4+
5+
case class Issue(n: String, list: List[Meh])

src/test/scala/issue/IssueTest.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package issue
2+
3+
import org.scalatest._
4+
import java.io.{ObjectOutputStream, ObjectInputStream, ByteArrayOutputStream, ByteArrayInputStream}
5+
6+
class IssueTest extends FunSuite with Matchers {
7+
test("serialization issue") {
8+
val obj = Issue("meh", List(Meh("2345")))
9+
val arr = serialize(obj)
10+
val obj2 = deserialize(arr)
11+
assert(obj === obj2)
12+
}
13+
14+
15+
def serialize[A <: Serializable](obj: A): Array[Byte] = {
16+
val o = new ByteArrayOutputStream()
17+
val os = new ObjectOutputStream(o)
18+
os.writeObject(obj)
19+
o.toByteArray()
20+
}
21+
22+
def deserialize[A <: Serializable](bytes: Array[Byte]): A = {
23+
val s = new ByteArrayInputStream(bytes)
24+
val is = new ObjectInputStream(s)
25+
is.readObject().asInstanceOf[A]
26+
}
27+
}

0 commit comments

Comments
 (0)