質問編集履歴
2
コードを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,49 +28,33 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
-
case class Data(a: String, b:
|
31
|
+
case class Data(a: String, b: Int)
|
32
|
-
|
33
|
-
case class SerializeSample[A](arr: Array[List[A]]) {
|
34
|
-
|
35
|
-
def serialize(): Unit = {
|
36
|
-
|
37
|
-
val oos = new ObjectOutputStream(Files.newOutputStream(Paths.get("SerializeSample.bin")))
|
38
|
-
|
39
|
-
oos.writeObject(this)
|
40
|
-
|
41
|
-
oos.close()
|
42
|
-
|
43
|
-
}
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
object SerializeSample {
|
48
|
-
|
49
|
-
def deserialize[A](): SerializeSample[A] = {
|
50
|
-
|
51
|
-
val ois = new ObjectInputStream(Files.newInputStream(Paths.get("SerializeSample.bin")))
|
52
|
-
|
53
|
-
val ret = ois.readObject().asInstanceOf[SerializeSample[A]]
|
54
|
-
|
55
|
-
ois.close()
|
56
|
-
|
57
|
-
ret
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
}
|
62
32
|
|
63
33
|
object Main {
|
64
34
|
|
65
35
|
def main(args: Array[String]): Unit = {
|
66
36
|
|
67
|
-
val
|
37
|
+
val arr: Array[List[Data]] = Array[List[Data]](List(Data("a", 97)))
|
68
38
|
|
69
|
-
val
|
39
|
+
val path = Paths.get("SerializeSample.bin")
|
70
40
|
|
71
|
-
s
|
41
|
+
// serialize
|
72
42
|
|
43
|
+
val oos = new ObjectOutputStream(Files.newOutputStream(path))
|
44
|
+
|
45
|
+
oos.writeObject(arr)
|
46
|
+
|
47
|
+
oos.close()
|
48
|
+
|
73
|
-
|
49
|
+
// deserialize
|
50
|
+
|
51
|
+
val ois = new ObjectInputStream(Files.newInputStream(path))
|
52
|
+
|
53
|
+
val ret = ois.readObject().asInstanceOf[Array[List[Data]]]
|
54
|
+
|
55
|
+
ois.close()
|
56
|
+
|
57
|
+
println(ret.mkString(" "))
|
74
58
|
|
75
59
|
}
|
76
60
|
|
@@ -82,17 +66,9 @@
|
|
82
66
|
|
83
67
|
sbt:sbt> run
|
84
68
|
|
85
|
-
[info] Compiling 1 Scala source to /home/kkkk/mnt/tmp/serializetest/sbt/target/scala-2.12/classes ...
|
86
|
-
|
87
|
-
[info] Done compiling.
|
88
|
-
|
89
|
-
[info] Packaging /home/kkkk/mnt/tmp/serializetest/sbt/target/scala-2.12/sbt_2.12-0.1.0-SNAPSHOT.jar ...
|
90
|
-
|
91
|
-
[info] Done packaging.
|
92
|
-
|
93
69
|
[info] Running Main
|
94
70
|
|
95
|
-
[error] (run-main-
|
71
|
+
[error] (run-main-13) java.lang.ArrayStoreException: scala.collection.immutable.List$SerializationProxy
|
96
72
|
|
97
73
|
[error] java.lang.ArrayStoreException: scala.collection.immutable.List$SerializationProxy
|
98
74
|
|
@@ -100,19 +76,9 @@
|
|
100
76
|
|
101
77
|
[error] at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1567)
|
102
78
|
|
103
|
-
[error] at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2287)
|
104
|
-
|
105
|
-
[error] at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2211)
|
106
|
-
|
107
|
-
[error] at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2069)
|
108
|
-
|
109
|
-
[error] at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)
|
110
|
-
|
111
79
|
[error] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:433)
|
112
80
|
|
113
|
-
[error] at SerializeSample$.deserialize(Main.scala:17)
|
114
|
-
|
115
|
-
[error] at Main$.main(Main.scala:
|
81
|
+
[error] at Main$.main(Main.scala:17)
|
116
82
|
|
117
83
|
[error] at Main.main(Main.scala)
|
118
84
|
|
@@ -166,4 +132,6 @@
|
|
166
132
|
|
167
133
|
[error] (Compile / run) Nonzero exit code: 1
|
168
134
|
|
135
|
+
[error] Total time: 0 s, completed 2018/02/04 15:59:19
|
136
|
+
|
169
137
|
```
|
1
OSを追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
scalaのシリアライズ
|
1
|
+
scalaのデシリアライズでエラーになる
|
test
CHANGED
@@ -13,6 +13,8 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
scalaのバージョンは2.12.4、sbtのバージョンは1.1.0です。
|
16
|
+
|
17
|
+
OSはCentOS7です。
|
16
18
|
|
17
19
|
```scala
|
18
20
|
|