我試圖對象發送到遠程的演員,我得到這個異常:NotSerializableException爲`地圖[字符串,字符串]`別名
ERROR akka.remote.EndpointWriter - Transient association error (association remains live)
java.io.NotSerializableException: scala.collection.immutable.MapLike$$anon$2
正在連載的對象是一個案例類:
case class LocationReport(idn: String, report: String, timestamp: Option[String], location: Attr, status: Attr, alarms: Attr, network: Attr, sensors: Attr) extends Message(idn) {
val ts = timestamp getOrElse location("fix_timestamp")
def json =
(report ->
("TIME" -> ts) ~
("location" -> location) ~
("alarms" -> alarms) ~
("network" -> network) ~
("sensors" -> ((status ++ sensors) + ("CUSTOMCLOCK" -> Report.decodeTimestamp(ts)))))
}
而且Attr
是一種重新定義:
type Attr = Map[String, String]
的Message
類很簡單:
abstract class Message(idn: String) {
def topic = idn
def json(): JValue
}
我想知道如果類型別名/重定義是令人困惑的序列化程序。我想我正在使用ProtoBuf序列化,但我確實在堆棧跟蹤中看到了JavaSerializer
。
更多的調試信息
我newed了JavaSerializer和單獨序列每個地圖。只有一個(alarms
)無法序列化。下面是他們每個人的的toString:
這一次失敗:
alarms = Map(LOWBATTERY -> 1373623446000)
這些成功:
location = Map(a_value -> 6, latitude -> 37.63473, p_value -> 4, longitude -> -97.41459, fix_timestamp -> 3F0AE7FF, status -> OK, fix_type -> MSBL, CUSTOMCLOCK -> 1373644159000)
network = Map(SID -> 1271, RSSI -> 85)
sensors = Map(HUMIDITY -> -999, PRESSURE -> -999, LIGHT -> -999 9:52 AM)
status = Map(TEMPERATURE_F -> 923, CYCLE -> 4, TEMPERATURE1_C -> 335, CAP_REMAINING -> 560, VOLTAGE -> 3691, CAP_FULL -> 3897)
類型別名與此完全無關。這是一個運行時問題,類型別名僅在編譯時存在。 – ghik
如果您尚未爲您的類定義protobuf協議並正在使用這些協議,那麼您並未使用ProtobufSerialization。 –
@ViktorKlang我將其更改爲JavaSerialization,它仍然無法正常工作。我認爲它與序列化Map相關,正如@ghik指出的那樣,這不是由別名引起的。有任何想法嗎? – kelloti